Data类的使用

时间日期格式转换

Time Limit: 1000MS  Memory Limit: 65536KB

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;="" \"="" style="box-sizing: border-box;">接下来的总共T行,每行都是一个需要转换的时间日期字符串。

Output

 分行输出转换之后的结果

Example Input

2
2010/11/20-12:12:12
1970/01/01-00:01:01

Example Output

11/20/2010-12:12:12pm

01/01/1970-12:01:01am

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws ParseException{
		Scanner in=new Scanner(System.in);
		int n;
		n=in.nextInt();
		while(n>0)
		{
			n--;
			String str=in.next();
			SimpleDateFormat s1=new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss");
			SimpleDateFormat s2=new SimpleDateFormat("MM/dd/yyyy-hh:mm:ssa",new Locale("US"));
			System.out.println(s2.format(s1.parse(str)).toLowerCase());
		}
		
	}

}


猜你喜欢

转载自blog.csdn.net/beautiful77moon/article/details/70473954
今日推荐