12:00[am] -- 11:59[am] 12:59[am]是夜里的00:59
12:00[pm] -- 11:59[pm] 12:59[pm]是中午的12:59
00:00 00:59 01:00 11:59 12:00 12:59 13:00 23:59 00:00
12:00am 12:59am 01:00am 11:59am 12:00pm 12:59pm 01:00pm 11:59pm 12:00am
/**
* 24小时制转12小时制
*
* HH:mm -> hh:mm
* SimpleDateFormat df = new SimpleDateFormat("hh:mm");
* String data = df.format(df.parse(dataString));
*/
public static String convert24HourTo12Str(String timeStr){
String resultStr = "";
String[] times = timeStr.split(":");
if(times!= null && times.length==2) {
int hour = Integer.parseInt(times[0]);
if (0 == hour){
resultStr = "AM " + "12:" + times[1];
} else if (hour < 12) {
resultStr = "AM " + timeStr;
} else if (hour == 12){
resultStr = "PM " + timeStr;
} else {
String hourStr = mHourFormatter.format(hour - 12);
resultStr = "PM " + hourStr + ":" + times[1];
}
}
return resultStr;
}
public static NumberPickerServier.Formatter mHourFormatter = new NumberPickerServier.Formatter() {
@Override
public String format(int value) {
String temp = "";
if (value < 10) {
temp = "0" + String.valueOf(value);
} else {
temp = String.valueOf(value);
}
return temp;
}
};