1. Get the current time:
Import Java.text.SimpleDateFormat; SimpleDateFormat Formatter = new simpledateformat ("YYYY year mm month DD Day hh:mm: SS "); Date curdate = new date (System.currenttimemillis ()); Gets the current time of the String str = Formatter.format (curdate);
2. you can get the current year or month, or you can write separately:
SimpleDateFormat Sdateformat = new SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss"); String date = Sdateformat.format (new java.util.Date ());
3. If you want to get the current month or year, you can write this (just get the time or the second type):
SimpleDateFormat sdf=New SimpleDateFormat ("yyyy-mm"); String Date=sdf.format (new java.util.Date ());
4. and of course, time zone can be specified (pending):
df=dateformat.getdatetimeinstance (Dateformat.full,dateformat.full,locale.china); System.out.println (Df.format(new Date ()));
5. How to get the Android system time is 24 hour or 12 hour system
This . Getcontentresolver (); = android.provider.Settings.System.getString (CV, android.provider.Settings.System.TIME_12_24); if (Strtimeformat.equals (") ") { log.i ("activity", "+"); }
Calendar C = calendar.getinstance (); = C.get (calendar.year) = c.grt (calendar.month) = c.get (calendar.day_of_month) = C.get (calendar.hour_of_day); = C.get (Calendar.minute)
6. Use the calendar to get
Calendar C =calendar.getinstance (); Get system date: year=C.get (calendar.year) Month=c.grt (calendar.month) Day=C.get (calendar.day_of_month) Acquisition system time: Hour=C.get (Calendar.hour_of_day); Minute=c.get (Calendar.minute) Calendar c=calendar.getinstance (); Get system date: year=C.get (calendar.year) Month=c.grt (calendar.month) Day=C.get (calendar.day_of_month) Acquisition system time: Hour=C.get (Calendar.hour_of_day); Minute= C.get (Calendar.minute)
7. Use Time to get
time T=// T.settonow (); get system time. int year = T.year; int month = T.month; int date = T.monthday; // 0-23 int minute = T.minute;