如何判断是不是BST我有下面的代码,应该返回偏移量60(显示当前在英国,我们在BST-即60分钟格林威治标准时间之前):varinfo=TimeZoneInfo.FindSystemTimeZoneById("格林威治标准时间");DateTimeOffsetlocalServerTime=DateTimeOffset.Now;doubleoff=localServerTime.Offset.TotalMinutes;返程;但是,它返回0。任何人都可以帮我解决这个问题吗?使用TimeZoneInfo.IsDaylightSavingTime方法(DateTimeOffset)查明当前是否为您的时区保存了夏令时。varinfo=TimeZoneInfo.FindSystemTimeZoneById("格林威治标准时间");DateTimeOffsetlocalServerTime=DateTimeOffset.Now;boolisDaylightSaving=info.IsDaylightSavingTime(localServerTime);以下是其他示例如果您得到0并且居住在英国,则您的计算机配置不正确。可能的原因是:谨慎进行彻底的更改,如果配置错误,可能会故意解决服务器上运行的关键业务应用程序中的某些缺陷。与管理服务器的人交谈。另一种选择是使用野田时间。以下代码适用于NodaTime1.4及更高版本:varzone=NodaTime.TimeZones.TzdbDateTimeZoneSource.Default.ForId("Europe/London");varzonedClock=NodaTime.SystemClock.Instance.InZone(zone);varzonedDateTime=zonedClock.GetCurrentZonedDateTime();boolisDST=zonedDateTime.IsDaylightSavingTime();控制台.WriteLine(isDST);对于早期版本的Noda,ZonedClock不可用,我们可以这样做:varzone=NodaTime.TimeZones.TzdbDateTimeZoneSource.Default.ForId("Europe/London");varnow=Instant.FromDateTimeOffset(DateTimeOffset.Now);varzonedDateTime=newZonedDateTime(now,zone);boolisDST=zonedDateTime.IsDaylightSavingTime();要处理从一个时区到另一个时区的转换,您需要查看支持的内容(如何?)以及不支持的内容。foreach(vartzinTimeZoneInfo.GetSystemTimeZones()){Console.WriteLine("TimeZoneOffset:{0}Name:{1},SupportsDLS:{2}",tz.BaseUtcOffset,tz.StandardName,tz.SupportsDaylightSavingTime);这应该为您提供所有时区的列表,包括有关夏令时的信息。注意:时区偏移量:00:00:00名称:格林威治标准时间,支持DLS:假时区偏移量:00:00:00名称:GMT标准时间,支持DLS:真所以,您需要使用“GMT标准时间”,因为它已经支持夏令时了。无需工作。这是示例代码:以上就是C#学习教程:如何判断是否是英国夏令时分享的全部内容。如果对大家有用,需要详细了解C#学习教程,希望大家多加关注—privatestaticstringGetBSTTimeStamp(stringtimestamp){DateTimedt=DateTime.Parse(timestamp);//TimeZoneInfobst=TimeZoneInfo.FindSystemTimeZoneById("GMT标准时间");//Console.WriteLine("时区是否支持dls?{0}",bst.SupportsDaylightSavingTime);//Console.WriteLine("时区偏移量?{0}",bst.BaseUtcOffset);DateTimedateTimeInUtc=TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dt,"东部标准时间","GMT标准时间");返回dateTimeInUtc.ToString();}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
