2246 时间日期格式转换

╰+攻爆jí腚メ 2022-05-26 05:30 384阅读 0赞

时间日期格式转换

Time Limit: 1000 ms Memory Limit: 65536 KiB

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

  1. 2
  2. 2010/11/20-12:12:12
  3. 1970/01/01-00:01:01

Sample Output

  1. 11/20/2010-12:12:12pm
  2. 01/01/1970-12:01:01am
  3. import java.util.*;
  4. public class Main {
  5. public static void main(String[] args) {
  6. Scanner cin = new Scanner(System.in);
  7. int n = cin.nextInt();
  8. while(n!=0) {
  9. int []a=new int [10];
  10. String str = cin.next();
  11. String []time = str.split("\\D");
  12. for(int i=0;i<6;i++) {
  13. a[i]=Integer.parseInt(time[i]);
  14. }
  15. int flag=0;
  16. if(a[3]>=12) {
  17. a[3]-=12;
  18. flag =1;
  19. }
  20. if(a[3]==0) {
  21. a[3]=12;
  22. }
  23. System.out.printf("%02d/%02d/%d-%02d:%02d:%02d",a[1],a[2],a[0],a[3],a[4],a[5]);
  24. if(flag==0) {
  25. System.out.println("am");
  26. }
  27. else {
  28. System.out.println("pm");
  29. }
  30. }
  31. cin.close();
  32. }
  33. }

发表评论

表情:
评论列表 (有 0 条评论,384人围观)

还没有评论,来说两句吧...

相关阅读