为什么Time在转换为long时会做出奇怪的事情? Java的

时间:2018-03-29 22:21:09

标签: java time long-integer

      public String toString(){
        Node temp = head;
        while(temp.next!=null){
            System.out.print(temp.value+" -> ");
            temp = temp.next;
        }
        System.out.print(temp.value);
        return " END List Count is "+listCount;

}

我想将时间值转换为秒,以便进行加法和减法操作。

1 个答案:

答案 0 :(得分:1)

我认为您在英国运行此代码。或者至少,在默认时区为Europe/London的JVM上。或者至少是在Unix时代比UTC早1小时的时区。

Here's an Ideone demo

    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Time t = Time.valueOf("00:00:00");
    long l = t.getTime(); // why is l -3600000
    System.out.println(l);

原因是伦敦在Unix时代节省了永久的夏令时,因此伦敦时代的实际时间是1970/1/1 01:00:00。

因此,该时区的1970/1/1 00:00:00为纪元之前的60分钟(或3600000毫秒)。

Here's a fork of the same demo, setting the timezone to UTC。这打印为零。