相关疑难解决方法(0)

为什么在1971年11月1日之前将一小时添加到java.util.Date的日期?

以下代码似乎演示了java.util.Date中的一个错误,如果本地时钟设置为GMT且DST调整开启且时间早于1971年11月1日,则会添加一小时.我的第一个假设始终是我的弄错了.任何人都可以看到什么是错的(或者这真的是一个Java错误)?1971年11月1日有什么重要意义?

import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.TimeZone;

class JavaUtilDateBug
{
    private static void demo() throws Exception
    {
        // UK developers usually have the clock on their development machines set
        // to "Europe/London" (i.e. GMT with daylight saving). Set it explicitly 
        // here so readers in other countries can see the problem too.
        TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
        Locale.setDefault(Locale.ENGLISH);

        SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
        String strJan1st1970Expected = "Thu Jan 01 00:00:00 GMT 1970";
        String strJan1st1970Actual = dateFormat.parse(strJan1st1970Expected).toString();
        System.out.println("strJan1st1970Actual: " + …
Run Code Online (Sandbox Code Playgroud)

java datetime

18
推荐指数
3
解决办法
1711
查看次数

标签 统计

datetime ×1

java ×1