Android development: Get the system time in the 12/24-hour format, android12
// Obtain the system time String currentTime = DateFormat through DateFormat. format ("yyyy-MM-dd hh-mm-ss", new Date ()). toString (); currentTime = "time obtained through DateFormat: \ n" + currentTime; // obtain the 24-hour time SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH-mm-ss", Locale through SimpleDateFormat. getDefault (); currentTime + = "\ n" + "Get the 24-hour time through SimpleDateFormat: \ n" + sdf. format (new Date (); // obtain the 12-hour time sdf = new SimpleDateFormat ("yyyy-MM-dd hh-mm-ss", Locale. getDefault (); currentTime + = "\ n" + "use SimpleDateFormat to obtain the 12-hour time: \ n" + sdf. format (new Date ());
Note: Only the 12-hour time can be obtained through DateFormat.
How does android determine whether the system time is day or night?
You need to obtain the processing time during the day or night. However, the system time is in the 12-hour format, and does not show the day or night. Even if I change my cell phone to the 24-hour format, the time is also in the 12-hour format. It is similar that it cannot be divided into seven o'clock in the daytime or seven o'clock in the evening. Another problem is that in case the user uses the 12-hour system, I cannot judge it. Can you help me determine whether it is daytime or evening. Thank you. ------ Solution else this is difficult to judge through the client. The client time can be changed at Will ------ solution -------------------------------------------------------- yes, the AM and PM values in the 12-hour format represent the ContentResolver cv = getBaseContext () in the morning and afternoon respectively (). getContentResolver (); String strTimeFormat = android. provider. settings. system. getString (cv, android. provider. settings. system. TIME_12_24); if (strTimeFormat! = Null & strTimeFormat. equals ("24") {Log. I ("Debug", "24-hour system");} else {String amPmValues; Calendar c = Calendar ar. getInstance (); you do not need to care whether the user's time is 12 hours or 24 hours, as long as the time is correct,
Android obtains the system time
The Time obtained is in the 24-hour format. It is difficult to use it on your mobile phone. It may be because the Time format you set on your mobile phone is not in the 24-hour format!