from:http://blog.csdn.net/feifei454498130/article/details/6540133ImportJava.text.SimpleDateFormat; SimpleDateFormat Formatter=NewSimpleDateFormat ("yyyy mm month DD Day HH:MM:SS"); Date curdate=NewDate (System.currenttimemillis ());//Get current TimeString str =Formatter.format (curdate); You can get the current year or month, or you can write separately: [Java] View Plaincopyprint?SimpleDateFormat Sdateformat=NewSimpleDateFormat ("Yyyy-mm-dd hh:mm:ss"); String Date= Sdateformat.format (Newjava.util.Date ()); If you want to get the current month and year, you can write this (just get the time or the second): Java code [Java] View Plaincopyprint?SimpleDateFormat SDF=NewSimpleDateFormat ("yyyy-mm"); String Date=sdf.format (Newjava.util.Date ()); And, of course, the time zone can be specified (pending): [Java] View Plaincopyprint?DF=dateformat.getdatetimeinstance (Dateformat.full,dateformat.full,locale.china); System.out.println (Df.format (NewDate ()));
how to get the Android system time is 24 hour or 12 hour system
[Java] view Plaincopyprint? this. Getcontentresolver (); = android.provider.Settings.System.getString (CV, android.provider.Settings.System.TIME_12_24); if (Strtimeformat.equals (") ") { log.i ("activity", "+"); }
[Java] view Plaincopyprint? = 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)
Use Calendar to get
[Java] View plaincopyprint?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)
Use Time to get
[Java] View plaincopyprint? time t =new time (); // T.settonow (); // get system time. int year = T.year; int month = T.month; int date = T.monthday; int hour = t.hour; // 0-23 int minute = T.minute; int second = T.second;
Acquisition of system date and time in Android