[Java]View Plaincopyprint?
- Import Java.text.SimpleDateFormat;
- SimpleDateFormat formatter = new SimpleDateFormat ("yyyy mm month DD Day HH:mm:ss");
- Date curdate = new Date (System.currenttimemillis ()); Get current time
- String str = Formatter.format (curdate);
You can get the current year or month, or you can write separately:
[Java]View Plaincopyprint?
- SimpleDateFormat Sdateformat = new SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss");
- String date = Sdateformat.format (new Java.util.Date ());
If you want to get the current month and year, you can write this (just get the same time or seconds):
Java Code
[Java]View Plaincopyprint?
- SimpleDateFormat sdf=New SimpleDateFormat ("yyyy-mm");
- String Date=sdf.format (new Java.util.Date ());
Of course, there are times when you can specify a time zone (wait):
[Java]View Plaincopyprint?
- Df=dateformat.getdatetimeinstance (Dateformat.full,dateformat.full,locale.china);
- System.out.println (Df.format (new Date ()));
how to get the Android system time is 24 hour or 12 hour system
[Java]View Plaincopyprint?
- Contentresolver CV = this.getcontentresolver ();
- String Strtimeformat = android.provider.Settings.System.getString (CV,
- ANDROID.PROVIDER.SETTINGS.SYSTEM.TIME_12_24);
- if (strtimeformat.equals (")" )
- {
- LOG.I ("activity","24");
- }
[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)
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 (); //or Time T=new time ("Gmt+8"), plus time zone information.
- 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 only disadvantage is that the removal time is only 24 hours mode.
Acquisition of system date and time in Android