- import java.util.*;
- import java.text.*;
- class Demo{
- public static void main(String[] args)throws Exception{
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
- //读取键盘录入
- Scanner scanner = new Scanner(System.in);
- System.out.println("请输入火车出发时间:");
- String str1 = scanner.nextLine();
- Date date1 = sdf.parse(str1);
- System.out.println("请输入火车到站时间:");
- String str2 = scanner.nextLine();
- Date date2 = sdf.parse(str2);
- System.out.println("火车用时"+(date2.getTime()-date1.getTime())/(60*1000)+"分钟");
- }
- }
复制代码
|