[Java] View plaincopyprint?
- Import java. Text. simpledateformat;
- Simpledateformat formatter = new simpledateformat ("mm DD, yyyy hh: mm: SS ");
- Date curdate = new date (system. currenttimemillis (); // obtain the current time
- String STR = formatter. Format (curdate );
Import Java. text. simpledateformat; </P> <p> simpledateformat formatter = new simpledateformat ("YYYY mm dd hh: mm: SS "); <br/> date curdate = new date (system. currenttimemillis (); // obtain the current time <br/> string STR = formatter. format (curdate); <br/> You can obtain the current date and month, or write separately: [Java] View plaincopyprint?
- Simpledateformat sdateformat = new simpledateformat ("yyyy-mm-dd hh: mm: SS ");
- String date = sdateformat. Format (New java. util. Date ());
Simpledateformat sdateformat = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); <br/> string date = sdateformat. format (New Java. util. date ());
If you want to obtain the current year and month, you can write it like this (only get the same time or second ): Java code[Java] View plaincopyprint?
- Simpledateformat SDF = new simpledateformat ("yyyy-mm ");
- String date = SDF. Format (New java. util. Date ());
Simpledateformat SDF = new simpledateformat ("yyyy-mm"); <br/> string date = SDF. Format (New java. util. Date (); <br/> Of course, you can also specify the time zone (to be ): [Java] View plaincopyprint?
- DF = dateformat. getdatetimeinstance (dateformat. Full, dateformat. Full, locale. China );
- System. Out. println (DF. Format (new date ()));
DF = dateformat. getdatetimeinstance (dateformat. Full, dateformat. Full, locale. China); <br/> system. Out. println (DF. Format (new date ())); |
How to obtain whether the Android system is in the 24-hour or 12-hour format
[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 ");
- }
Contentresolver CV = This. getcontentresolver (); <br/> string strtimeformat = android. provider. settings. system. getstring (CV, <br/> android. provider. settings. system. time_12_24); </P> <p> If (strtimeformat. equals ("24") <br/>{< br/> log. I ("activity", "24"); <br/>}
[Java]
View plaincopyprint?
- Calendar c = calendar. getinstance ();
- Obtain the system date: year = C. Get (calendar. Year)
- Month = C. GRT (calendar. month)
- Day = C. Get (calendar. day_of_month)
- Obtain the system time: hour = C. Get (calendar. hour_of_day );
- Minute = C. Get (calendar. Minute)
Calendar c = calendar. getinstance (); <br/> system date: year = C. get (calendar. year) <br/> month = C. GRT (calendar. month) <br/> day = C. get (calendar. day_of_month) <br/> obtain the system time: hour = C. get (calendar. hour_of_day); <br/> minute = C. get (calendar. minute)
Obtain from calendar
[Java]
View plaincopyprint?
- Calendar c = calendar. getinstance ();
- Obtain the system date: year = C. Get (calendar. Year)
- Month = C. GRT (calendar. month)
- Day = C. Get (calendar. day_of_month)
- Obtain the system time: hour = C. Get (calendar. hour_of_day );
- Minute = C. Get (calendar. Minute)
- Calendar c = calendar. getinstance ();
- Obtain the system date: year = C. Get (calendar. Year)
- Month = C. GRT (calendar. month)
- Day = C. Get (calendar. day_of_month)
- Obtain the system time: hour = C. Get (calendar. hour_of_day );
- Minute = C. Get (calendar. Minute)
Calendar c = calendar. getinstance (); <br/> system date: year = C. get (calendar. year) <br/> month = C. GRT (calendar. month) <br/> day = C. get (calendar. day_of_month) <br/> obtain the system time: hour = C. get (calendar. hour_of_day); <br/> minute = C. get (calendar. minute) <br/> calendar c = calendar. getinstance (); <br/> system date: year = C. get (calendar. year) <br/> month = C. GRT (calendar. month) <br/> day = C. get (calendar. day_of_month) <br/> obtain the system time: hour = C. get (calendar. hour_of_day); <br/> minute = C. get (calendar. minute)
Obtain with time
[Java]
View plaincopyprint?
- Time t = new time (); // or time t = new time ("GMT + 8"); plus the time zone information.
- T. settonow (); // obtain 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;
Time t = new time (); // or time t = new time ("GMT + 8"); plus the time zone information. <Br/> T. settonow (); // obtain the system time. <Br/> int year = T. year; <br/> int month = T. month; <br/> int date = T. monthday; <br/> int hour = T. hour; // 0-23 <br/> int minute = T. minute; <br/> int second = T. second;
The only disadvantage is that the retrieval time is only in 24-hour mode.