没有午夜的一天 [英] A day without midnight
问题描述
在夏令时向前跳"时,至少有一个时区从 23:59:59 跳到 1:00:00.有人知道是什么吗?
以下内容通常会获取今天的日期,但对于符合上述条件的时区,它每年都会失败一天.
$ perl -MDateTime -E'say DateTime->today( time_zone => $ARGV[0] )->ymd;'\美国/纽约2013-08-28
我需要时区进行测试.我不是想让上面的代码工作.
有几个.截至 2020-04 年,在 10 个国家/地区有 14 个这样的时区:巴拉圭、古巴、智利、格陵兰/丹麦、约旦、黎巴嫩、叙利亚、巴勒斯坦、伊朗和亚速尔/葡萄牙.
在 2019 年 4 月之前,该列表包括巴西,使用美国/圣保罗
时区.
$ perl -MDateTime -E'say DateTime->new(年 =>2013 年,月 =>10, 天 =>20,小时=>12、时区 =>"America/Sao_Paulo")-> truncate( to => "day" )->ymd;'时区日期的当地时间无效:America/Sao_Paulo
您可以通过在获取日期之前切换到浮动"书本区域来解决该问题:
$ perl -MDateTime -E'say DateTime->new(年 =>2013 年,月 =>10, 天 =>20, 小时 =>12、时区 =>"美国/圣保罗")->set_time_zone("浮动")-> truncate( to => "day" )->ymd;'2013-10-20
请参阅本文档.>
There's at least one time zone that skips from 23:59:59 to 1:00:00 when "springing forward" for DST. Does anyone know what it is?
The following normally gets today's date, but it fails one day a year for time zones matching the above criterion.
$ perl -MDateTime -E'say DateTime->today( time_zone => $ARGV[0] )->ymd;' \
America/New_York
2013-08-28
I need the time zone for testing purposes. I'm not trying to get the above code to work.
There are several. As of 2020-04, there are 14 such time zones in 10 countries: Paraguay, Cuba, Chile, Greenland/Denmark, Jordan, Lebanon, Syria, Palestine, Iran, and Azores/Portugal.
Before 2019-04, the list included Brazil using the America/Sao_Paulo
time zone.
$ perl -MDateTime -E'say DateTime->new(
year => 2013, month => 10, day => 20, hour => 12,
time_zone => "America/Sao_Paulo")->truncate( to => "day" )->ymd;'
Invalid local time for date in time zone: America/Sao_Paulo
You can get around the problem by switching to the "floating" tome zone before getting the date:
$ perl -MDateTime -E'say DateTime->new(
year => 2013, month => 10, day => 20, hour => 12,
time_zone => "America/Sao_Paulo")
->set_time_zone("floating")
->truncate( to => "day" )
->ymd;'
2013-10-20
See this documentation.
这篇关于没有午夜的一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!