Problem Description
而北美所用的日期格式则为“月月/日日/年年年年”或”mm/dd /yyyy”,如将“2010/11/20”改成这种格式,对应的则是”11/20/2010”。对于时间的格式,则常有12小时制和24小时制
12小时制的表示方法是”05:30:00pm”。注意12:00:00pm表示中午12点,而12:00:00am 表示凌晨12点。
第一行为一个整数T(T<=20),代表总共需要转换的时间日期字符串的数目。
<span 18px;="" \"="">接下来的总共T行,每行都是一个需要转换的时间日期字符串。
Output
分行输出转换之后的结果
Sample Input
2 2010/11/20-12:12:12 1970/01/01-00:01:01
Sample Output
11/20/2010-12:12:12pm 01/01/1970-12:01:01am
Hint
Source
import java.util.*;
public class Main {
public static void main(String args[]){
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
int i;
cin.nextLine();
for(i = 0; i < n; i++){
String s = cin.nextLine();
int z = s.indexOf("-");
String a = s.substring(0,z);
String b = s.substring(z+1);
String f1[] = a.split("/");
String f2[] = b.split(":");
int hour = Integer.parseInt(f2[0]);
int minute = Integer.parseInt(f2[1]);
int second = Integer.parseInt(f2[2]);
String f = new String();
if(hour >= 12){
f = "pm";
}else{
f = "am";
}
if(hour > 12){
hour = hour - 12;
}else if(hour == 0){
hour = 12;
}
System.out.printf("%s/%s/%s-%02d:%02d:%02d%s\n",f1[1],f1[2],f1[0],hour,minute,second, f);
}
}
}