gpt4 book ai didi

vb.net - 欧洲/都柏林的 NodaTime DST 问题

转载 作者:行者123 更新时间:2023-12-05 03:51:09 31 4
gpt4 key购买 nike

我正在尝试两种不同的方法来确定 NodaTime 的夏令时:

now = SystemClock.Instance.GetCurrentInstant

Dim nowInIsoUtc As String = now.InUtc.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)
Dim localTimeZone As DateTimeZone = DateTimeZoneProviders.Tzdb(ComboBox1.SelectedItem.ToString)
Dim nowInLocal As String = now.InZone(localTimeZone).ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)
Dim DST As Boolean = now.InZone(localTimeZone).IsDaylightSavingTime
Dim interval As ZoneInterval = localTimeZone.GetZoneInterval(now)
Dim DstStart As Instant = interval.Start
Dim DstEnd As Instant = interval.End
' Gets the Daylight Savings value for this period
Dim DstSavings As Offset = interval.Savings
' Gets the Standard Offset for this period without any Daylight Savings contributions
Dim StandardOffset As Offset = interval.StandardOffset
Tb1.AppendText("Current DateTime in UTC: " & nowInIsoUtc & vbCrLf)
Tb1.AppendText("Current DateTime in Local Time: " & nowInLocal & vbCrLf)
Tb1.AppendText("Local TimeZone: " & localTimeZone.ToString & vbCrLf)
Tb1.AppendText("Amount of Daylight Savings in hours: " & DstSavings.ToString & vbCrLf)
Tb1.AppendText("StandardOffset: " & StandardOffset.ToString & vbCrLf)
Tb1.AppendText("DST: " & DST.ToString & ". From " & DstStart.ToString & " to " & DstEnd.ToString & vbCrLf)

Dim SelectedZone As DateTimeZone = DateTimeZoneProviders.Tzdb(ComboBox1.SelectedItem.ToString)
Dim clock As ZonedClock = SystemClock.Instance.InZone(SelectedZone)
Dim ThisDate As LocalDate = clock.GetCurrentDate()
Dim ThisTime As LocalTime = clock.GetCurrentTimeOfDay
Dim DST As Boolean = clock.GetCurrentZonedDateTime.IsDaylightSavingTime

Tb1.AppendText("DateTime in selected Zone: " & SelectedZone.ToString & vbCrLf)
Tb1.AppendText("Date: " & ThisDate.ToString & ", Time: " & ThisTime.ToString & " DST: " & DST & vbCrLf)

当使用“欧洲/都柏林”和“欧洲/伦敦”作为时区时,我得到了相互矛盾的结果:

METHOD A:
Current DateTime in UTC: 2020-07-29 08:46:27

Current DateTime in Local Time: 2020-07-29 09:46:27
Local TimeZone: Europe/Dublin
Amount of Daylight Savings in hours: +00
StandardOffset: +01
DST: False. From 2020-03-29T01:00:00Z to 2020-10-25T01:00:00Z

Current DateTime in UTC: 2020-07-29 08:46:46
Current DateTime in Local Time: 2020-07-29 09:46:46
Local TimeZone: Europe/London
Amount of Daylight Savings in hours: +01
StandardOffset: +00
DST: True. From 2020-03-29T01:00:00Z to 2020-10-25T01:00:00Z
METHOD B:
DateTime in selected Zone: Europe/Dublin
Date: Wednesday, 29 July, 2020, Time: 09:47:03 DST: False

DateTime in selected Zone: Europe/London
Date: Wednesday, 29 July, 2020, Time: 09:47:09 DST: True

这两种方法似乎都表明都柏林没有夏令时,即使两者给出了相同的 DST 开始和结束日期/时间。请问有什么想法吗?

最佳答案

结果是正确的 - 这是爱尔兰时区的一个奇怪之处。目前爱尔兰遵守夏令时。它的标准偏移量是UTC+1。

2020 年 10 月 25 日,爱尔兰将进入“夏令时”,夏令时偏移量为 -1 小时。因此,如果您将测试更改为尝试 11 月的日期(例如),您将看到 Europe/Dublin 显示 DST:True 和 Europe/London 显示 DST:False。

自 1968 年以来,爱尔兰一直如此。以下是来自 IANA database 评论中的相关信息。 :

# (Note that the time in the Republic of Ireland since 1968 has been defined
# in terms of standard time being GMT+1 with a period of winter time when it
# is GMT, rather than standard time being GMT with a period of summer time
# being GMT+1.)

关于vb.net - 欧洲/都柏林的 NodaTime DST 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63150152/

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