Android Top Tip: Get the current date and time

Android Get the current date and timeHere’s a code snipped to get the current date and/or time. This snipped uses the Calendar object (java.util.Calendar) which is an useful class when working with dates.

//Get a calendar object for the current date and time
Calendar currentDateTime = Calendar.getInstance();
//Example: Get current day of the month
int CurrentDay = currentDateTime.get(Calendar.DAY_OF_MONTH);
//Example: Get current minutes
int CurrentMinutes = currentDateTime.get(Calendar.MINUTE);

More information

For more information see the Android SDK reference guide:
http://developer.android.com/reference/java/util/Calendar.html

Leave a Reply

Your email address will not be published. Required fields are marked *