Timezone和SimpleDateFormat奇怪的行为

问题描述 投票:1回答:1

如果我执行此代码:

String data = "08/02/1941";
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = dateFormat.parse(data);

我在输出日期:Sat Feb 08 01:00:00 CEST 1941

相反,如果我执行此代码:

String data = "08/02/1971";
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = dateFormat.parse(data);

日期是:Sat Feb 08 01:00:00 CET 1971

为什么我会有这种差异(CET和CEST)?

我的时区是Europe / Berlin(UTC + 1),我正在使用Java 1.7.0_67-b01

java datetime timezone simpledateformat
1个回答
2
投票

War Time — Shifting Time Zones

夏令时是柏林的observed all year long in 1941。根据这个history of DST in Europe.,一些人称为“希特勒时间”

战争期间和战后欧洲shifted around dramatically的时区。例如,this post(据称来自格林威治皇家天文台)描述了其中一些变化,包括“双重”DST。这些转变是时区在历史中发挥重要作用的有趣案例。 At least one academic使用“chronopolitics”一词来表示这种现象。

Date-only

如果您想要表示没有时间且没有时区的日期,请使用LocalDate classe。

LocalDate ld = LocalDate.of( 1941 , Month.FEBRUARY , 8 ) ;

ld.toString():1941-02-08

上面讨论的时区问题逐渐消失。

© www.soinside.com 2019 - 2024. All rights reserved.