我正在实现DST复选框,如果需要,则在复选框启用时调整时钟,如果复选框处于关闭状态,则不考虑DST,
假设开始夏令时,时钟提前一小时所以这里有两次-原始时间和调整时间我如何检索这两个时间?
在New York (-04)
处Sun, Mar 8 at 2:00 am
处,DST开始,因此时钟调整为+1小时。所以有原始时间和调整时间在原始时间Sun, Mar 9 at 8:00 am
,时钟显示调整后的时间Sun, Mar 9 at 9:00 am
在美国以外的地方,给定输入current universal time
,我想在纽约检索original time
和DST adjusted time
。
输入/输出-更新03/05这是实现上述目标的正确方法吗?
string fromZoneId = "Asia/Kolkata";
string toZoneId = "America/New_York";
var fromDateTime = DateTime.Parse("March 9, 2020");//Input kolkata time
LocalDateTime fromLocal = LocalDateTime.FromDateTime(fromDateTime);
DateTimeZone fromZone = DateTimeZoneProviders.Tzdb[fromZoneId];
ZonedDateTime fromZoned = fromLocal.InZoneLeniently(fromZone);
DateTimeZone toZone = DateTimeZoneProviders.Tzdb[toZoneId];
ZonedDateTime toZoned = fromZoned.WithZone(toZone);
LocalDateTime toLocal = toZoned.LocalDateTime;
var interval = toZoned.GetZoneInterval();
var savings = interval.Savings;
var originalTime = toLocal.ToDateTimeUnspecified().AddSeconds(-savings.Seconds);
var dstAdjustedTime = toLocal.ToDateTimeUnspecified();
Console.WriteLine("Actual:"+ originalTime);//output-dst off
Console.WriteLine("Adjusted:"+ dstAdjustedTime);//output-dst on
我正在实现DST复选框,如果需要,可以调整复选框的启用时间,如果复选框处于关闭状态,那么就不考虑DST,假设DST开始时,时钟提前了一个小时,所以这里...
在您的示例中,我将要更改的是留在Noda进行BLC之前的所有转换。这样,您可以利用WithOffset()方法并使用StandardOffset而不是自己在BLC中进行算术]