zoukankan      html  css  js  c++  java
  • SDUT 1177 C语言实验——时间间隔

    C语言实验——时间间隔

    Time Limit: 1000MS Memory Limit: 65536KB

    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实现

     1 import java.util.Scanner;
     2 import java.util.Date;
     3 import java.util.TimeZone;
     4 import java.text.SimpleDateFormat;
     5 import java.lang.Math;
     6 
     7 public class Main{
     8     public static void main(String[] args) throws Exception {
     9         SimpleDateFormat fd=new SimpleDateFormat("HH:mm:ss");
    10         Scanner input=new Scanner(System.in);
    11         Date t1=fd.parse(input.next());
    12         Date t2=fd.parse(input.next());
    13         long t=Math.abs(t2.getTime()-t1.getTime());
    14         fd.setTimeZone(TimeZone.getTimeZone("GMT+0"));
    15         System.out.println(fd.format(t));
    16     }
    17 }
    18 
    19 /***************************************************
    20 User name: ***
    21 Result: Accepted
    22 Take time: 196ms
    23 Take Memory: 11900KB
    24 Submit time: 2017-05-18 15:48:06
    25 ****************************************************/
  • 相关阅读:
    扩展欧几里得算法
    单源最短路径—Dijkstra算法
    欧拉定理,费马小定理
    欧拉函数
    Trie 字典树
    平衡树——Treap,Splay
    NOI2009 开关
    银河英雄传说
    线段树与延迟标记
    c++常见变量的极值
  • 原文地址:https://www.cnblogs.com/Leroscox/p/6873807.html
Copyright © 2011-2022 走看看