gpt4 book ai didi

Java SimpleDateFormat 为不同的日期提供不同的时区

转载 作者:搜寻专家 更新时间:2023-11-01 02:24:55 24 4
gpt4 key购买 nike

我在解析日期时有一个奇怪的行为。给定

DateFormat sdf= new SimpleDateFormat("dd/MM/yyyy");

sdf.parse("25/10/2014") 返回 2014 年 10 月 25 日 00:00:00 BST

同时

sdf.parse("27/10/2014") 返回 2014 年 10 月 27 日 00:00:00 GMT

我发现这是因为夏令时的变化,但我当然希望同一个解析器返回同一个时区。还是我错了?

最佳答案

根据关于 British Summer Time 的维基百科文章

During British Summer Time (BST), civil time in the United Kingdom is advanced one hour forward of Greenwich Mean Time (GMT), so that evenings have more daylight and mornings have less

BST begins at 01:00 GMT on the last Sunday of March and ends at 01:00 GMT (02:00 BST) on the last Sunday of October.

2014 年 10 月的最后一个星期日是 26 号。因此,时区从英国夏令时更改为英国的格林尼治标准时间。

默认时区是您的系统时区,因此当它改变时您的解析器也会改变。

关于Java SimpleDateFormat 为不同的日期提供不同的时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27042494/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com