DSTJZ


私信TA

用户名:dotcpp0721777

访问量:5483

签 名:

天下难事,必作于易;天下大事,必作于细。

等  级
排  名 48
经  验 11318
参赛次数 13
文章发表 322
年  龄 18
在职情况 学生
学  校 狗熊岭23届毕业生
专  业

  自我简介:

TA的其他文章

java--study||O.o
浏览:20
java--study||O.o
浏览:23
java--study||O.o
浏览:26


参考代码:

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

public class Main
{   static Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) throws ParseException//日期时间格式的抛异常
    {   int n = scanner.nextInt();
        scanner.nextLine();
        while(n-- > 0)
        {   int to = getTime();
            int back = getTime();
            int res = (to + back) / 2;//飞去的时间时是:飞行时间-时差,回来的时间是:飞行时间+时差
            System.out.printf("%02d:%02d:%02d\n", res / 3600, res / 60 % 60, res % 60); //printf前置0,防空位
        }
    }
    static int getTime() throws ParseException
    {   String[] in = scanner.nextLine().split(" ");
        SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");//format类的自定义时间格式匹配
        Date start = format.parse(in[0]);
        Date end = format.parse(in[1]);
        int t = 0;
        if(in.length > 2)
            t = Integer.parseInt(in[2].substring(2, 3));
        return (int) ((end.getTime() - start.getTime()) / 1000 + t * 24 * 3600);//Date类返回的是纳秒
    }
}


 

0.0分

0 人评分

  评论区