题解 | #日期换算#
日期换算
https://www.nowcoder.com/practice/08f8a66cb5584268a78ecca2749a2da5
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Scanner in = new Scanner(System.in);
String str1 = in.nextLine();
//write your code here......
String str[]=str1.split(" ");
if(str.length!=6)
System.out.println("您输入的数据不合理");
else
{
String tmp=str[0]+"-"+str[1]+"-"+str[2]+" "+str[3]+":"+str[4]+":"+str[5];
Date d=sdf.parse(tmp);
System.out.println("北京时间为:"+sdf.format(d.getTime()));
System.out.println("纽约时间为:"+sdf.format(d.getTime()-(long)12*60*60*1000));
}
}
}
曼迪匹艾公司福利 141人发布
查看5道真题和解析