First of all, first of all, the following Java can be used in a normal way:
1 ImportJava.text.DateFormat;2 ImportJava.text.SimpleDateFormat;3 ImportJava.util.Calendar;4 Importjava.util.Date;5 ImportJava.util.Locale;6 7 Public classGetDate {8 9 /**Ten * @paramargs One */ A Public Static voidMain (string[] args) { - - //Get date and time (12 hour system) theSimpleDateFormat Sdateformat =NewSimpleDateFormat ( -"Yyyy-mm-dd hh:mm:ss");//Show Rules -String date = Sdateformat.format (Newjava.util.Date ()); - + System.out.println (date); - + //Get date and time (12 hour system) ASimpleDateFormat SDATEFORMAT1 =NewSimpleDateFormat ( at"yyyy mm month DD Day Hh:mm:ss");//Show Rules -String date1 = Sdateformat.format (Newjava.util.Date ()); - - System.out.println (date1); - - //set the time zone to display times using the date () method inDateFormat df=dateformat.getdatetimeinstance (Dateformat.full,dateformat.full,locale.china);//China -System.out.println (Df.format (NewDate ())); to + //24 Hour System -Calendar C =calendar.getinstance (); the //Get system Date: * intYear =C.get (calendar.year); $ intmonth = C.get (calendar.month) +1;//get 1 less months than the real monthPanax Notoginseng intDay =C.get (calendar.day_of_month); - //Get system time: the inthour =C.get (Calendar.hour_of_day); + intminute =C.get (calendar.minute); A theSystem.out.println (year+ ":" +month+ ":" +day+ ":" +hour+ ":" +minute+ ""); + - //Time t=new time ();//or time T=new time ("Gmt+8"), plus time zone data. $ } $ -}
Can directly test to run on the computer to see the difference.
Here are the results:
2016-03-08 12:35:342016-03-08 12:35:34March 8, 2016 Tuesday 12:35 A.M. 34 sec CST2016:3:8:0:35
Below you can put down the methods available for Android:
= this .getcontentresolver (); String strtimeformat = Android.provider.Settings.System.getString (CV, ANDROID.PROVIDER.SETTINGS.SYSTEM.TIME_12_24); if (Strtimeformat.equals (" "Activity", "
take time to get: Java code: 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;
The two above have not been tested, but time acquisition is not recommended
Android Get time