SDUT 1177 C语言实验——时间间隔

2022-11-21,,,,

C语言实验——时间间隔

Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic Discuss

Problem Description

从键盘输入两个时间点(24小时制),输出两个时间点之间的时间间隔,时间间隔用“小时:分钟:秒”表示。
如:3点5分25秒应表示为--03:05:25.假设两个时间在同一天内,时间先后顺序与输入无关。

Input

输入包括两行。
第一行为时间点1。
第二行为时间点2。

Output

以“小时:分钟:秒”的格式输出时间间隔。
格式参看输入输出。

Example Input

12:01:12
13:09:43

Example Output

01:08:31

Java实现

 import java.util.Scanner;
import java.util.Date;
import java.util.TimeZone;
import java.text.SimpleDateFormat;
import java.lang.Math; public class Main{
public static void main(String[] args) throws Exception {
SimpleDateFormat fd=new SimpleDateFormat("HH:mm:ss");
Scanner input=new Scanner(System.in);
Date t1=fd.parse(input.next());
Date t2=fd.parse(input.next());
long t=Math.abs(t2.getTime()-t1.getTime());
fd.setTimeZone(TimeZone.getTimeZone("GMT+0"));
System.out.println(fd.format(t));
}
} /***************************************************
User name: ***
Result: Accepted
Take time: 196ms
Take Memory: 11900KB
Submit time: 2017-05-18 15:48:06
****************************************************/

SDUT 1177 C语言实验——时间间隔的相关教程结束。

《SDUT 1177 C语言实验——时间间隔.doc》

下载本文的Word格式文档,以方便收藏与打印。