有没有一种方法可以在不使用转换的情况下检查UTC是否为夏令时(Daylight Saving Time)?
我不想使用转换,因为在10月28日凌晨2点这个时间是模糊的。下面是一个例子:
using System;
namespace Rextester
{
public class Program
{
public static void PrintSeasonKindTime(DateTime utcDate)
{
// Convert dt to Romance Standard Time
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
DateTime localDate = TimeZoneInfo.ConvertTime(utcDate, tzi);
Console.WriteLine("Local date: " + localDate.ToString("yyyy.MM.d HH:mm:ss") + (tzi.IsDaylightSavingTime(localDate) ? " is summer" : " is winter"));
}
public static void Main(string[] args)
{
DateTime currentUTCDateTime = new DateTime(2018,10,27,23,59,0, DateTimeKind.Utc);
double nbMinutes = 1.0;
PrintSeasonKindTime(currentUTCDateTime);
PrintSeasonKindTime(currentUTCDateTime.AddMinutes(nbMinutes));
}
}
}
会显示这个:
Local date: 2018.10.28 01:59:00 is summer
Local date: 2018.10.28 02:00:00 is winter
虽然我希望以下内容能够展示出来:
Local date: 2018.10.28 01:59:00 is summer
Local date: 2018.10.28 02:00:00 is summer
由于夏令时变更发生在2018年10月28日当地时间03:00:00,而不是早上2点(请参见此处 链接说明)。
然而,这种行为是“含糊不清”的,因为在10月28日的两次2点之间存在时间差;一次在UTC 00:00(夏令时2点),一次在1点(冬令时2点)。你有什么想法吗?