Copy Code code as follows:
Import Java.text.SimpleDateFormat;
SimpleDateFormat formatter = new SimpleDateFormat ("YYYY year 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 so, or you can write separately:
Copy Code code as follows:
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 year, you can write this (get only time or seconds):
Java code
Copy Code code as follows:
SimpleDateFormat sdf=new SimpleDateFormat ("yyyy-mm");
String Date=sdf.format (New Java.util.Date ());
And, of course, the time zone can be specified (stay):
Copy Code code as follows:
Df=dateformat.getdatetimeinstance (Dateformat.full,dateformat.full,locale.china);
System.out.println (New Date ()) (Df.format);
How to get Android system time is 24-hour or 12-hour system
Copy Code code as follows:
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");
}
Copy Code code as follows:
Calendar C = calendar.getinstance ();
Get system date: Year = C.get (calendar.year)
month = C.GRT (calendar.month)
Day = C.get (calendar.day_of_month)
Get system time: Hour = C.get (Calendar.hour_of_day);
minute = C.get (Calendar.minute)
use calendar to get
Copy Code code as follows:
Calendar C = calendar.getinstance ();
Get system date: Year = C.get (calendar.year)
month = C.GRT (calendar.month)
Day = C.get (calendar.day_of_month)
Get 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)
Get system time: Hour = C.get (Calendar.hour_of_day);
minute = C.get (Calendar.minute)
Use time to get
Copy Code code as follows:
Time T=new time (); or time T=new time ("gmt+8"); Add time zone data.
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 problem is that the extraction time is only 24 hours mode.