[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 ("24"))
{
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"); Add time zone information.
T.settonow (); Get the 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.
Android Get system time