There is plenty of constants in the Calendar for everything you need. Edit:calendar class Documentation
The time class is a faster replacement for the Java.util.Calendar and Java.util.GregorianCalendar classes. An instance of the time class represents a moment in time, specified with second precision.
If you want to get the date and time of a specific pattern you can use the following:
SimpleDateFormat sdf =newSimpleDateFormat("yyyyMMdd_HHmmss");String currentDateandTime = sdf.format(newDate());
Actually, it ' s safer to set the current timezone set on Time.getCurrentTimezone()
the device with, or else you'll get the current time in UT C.
Time today =newTime(Time.getCurrentTimezone());today.setToNow();
Then, you can get all the date fields you want, like, for example:
Textviewday.SetText(Today.MonthDay+"");//day of the Month (1-31)Textviewmonth.SetText(Today.Month+"");//Month (0-11)Textviewyear.SetText(Today. Year+"");// yearTextviewtime.SetText(Today.format("%k:%m:%s"));// Current time
See Android.text.format.Time class for all the details.
To GE, the current time, can use which are standard in System.currentTimeMillis()
Java. Then you can use it to create a date
Date currentDate =newDate(System.currentTimeMillis());
And as mentioned by others to create a time
Time currentTime =newTime();currentTime.setToNow();
For those who might rather prefer a customized format, you can use:
DateFormat df =newSimpleDateFormat("EEE, d MMM yyyy, HH:mm");String date = df.format(Calendar.getInstance().getTime());
Whereas you can have dateformat patterns such as:
"yyyy. Mm.dd G ' at ' HH:mm:ss z '----2001.07.GenevaAD at A: ,: AboutPDT"hh ' o ' clock ' A, zzzz"----------- Ao' clock PM, Pacific Daylight Time ' EEE, D MMM yyyy HH:mm:ss Z '-------Wed, 4 Jul 2001 12:08:56-0700 ' Yyyy-mm-dd 'T' HH:mm:ss. Sssz "-------2001-07-04t12:08:56.235-0700" yymmddhhmmssz "--------------------010704120856-0700" k:mm A, z "--------- --------------0:08 pm, PDT "h:mm a"--------------------------12:08 PM "EEE, MMM D, ' yy"----------------Wed, Jul 4, '
01
Http://stackoverflow.com/questions/5369682/get-current-time-and-date-on-android