是否采取的TimeZoneInfo DST考虑? [英] Does TimeZoneInfo take DST into consideration?

查看:137
本文介绍了是否采取的TimeZoneInfo DST考虑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问C#时区之间进行转换时需要夏令时考虑?

Does C# take Daylight savings time into consideration when converting between timezones?

我这是在伦敦当前时间的源日期,我想转换到我的时区(CET)。这里是我正在使用的代码

I have a source date which is in the current time in London, and I want to convert it to my timezone (CET). Here's the code I'm using.

DateTime time = DateTime.ParseExact(timeString, "HH:mm", null);
time = DateTime.SpecifyKind(time, DateTimeKind.Unspecified);

//Convert it to the right timezone. It is currently in GMT

TimeZoneInfo gmt = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
TimeZoneInfo current = TimeZoneInfo.Local;

DateTime utc = TimeZoneInfo.ConvertTimeToUtc(time, gmt);
DateTime local = TimeZoneInfo.ConvertTimeFromUtc(utc, core.startTime = local;



这是目前运作良好。然而,当DST抚养它丑恶的头,它会继续工作,否则将打破可怕?我有点警惕时区由于有过去曾吨的问题。

It's currently working well. However when DST rears its ugly head, will it continue working or will it break horribly? I'm a bit wary of TimeZones due to having had tons of issues in the past.

推荐答案

TimeZoneInfo.GetAdjustmentRules会给你的规则的集合有关在DST更改偏移,当他们进入和走出去的效果。

TimeZoneInfo.GetAdjustmentRules will give you a collection of rules about changes in the DST offset and when they come into and go out of effect.

不过,您的用户仍然可以通过公鸡东西取消选中在Windows控制面板,日期和时间自动调整为夏令时,如果DST在Windows关闭了,那么你会得到一个空的集合调整规则。

However, your user can still cock things up by un-checking "Automatically adjust for daylight savings" in Windows Control Panel Date and Time. If DST is turned off in Windows then you will get an empty collection of adjustment rules.

如果你想要的,你必须使用该DateTimeKind已设置的DateTime对象调整规则自动魔法的应用程序。如果DST被关闭,这将在兑现转换。

If you want automagical application of adjustment rules you must use DateTime objects for which the DateTimeKind has been set. If DST is turned off this will be honoured in the conversion.

GMT是在格林尼治皇家天文台太阳时。英国人发明从日期变更线时区偏移的全业务,因为他们是第一批来协调在全球范围内任何东西。在以往的太平日子他们有帆船和没有收音机的行星范围内的海军。订单的滞后是几个星期或几个月,如此一致,精确的全球计时是由唯一的人与参考比地球大的框架发明 - 皇家天文学家

GMT is solar time at the Royal Observatory in Greenwich. The British invented the whole business of timezone offsets from a date-line because they were the first to coordinate anything on a global scale. In halcyon days of yore they had a planet-wide navy of sailboats and no radio. Lag on orders was weeks or months, so consistent, precise, global time-keeping was invented by the only people with a frame of reference larger than a planet - the Royal Astronomers.

月亮的引潮力正在放缓地球的自转。这需要大量的果汁来晃动的上下水的海洋,也没什么神奇的,它来自地球的自旋时刻。

The moon's tidal forces are slowing the Earth's rotation. It takes a lot of juice to slosh an ocean of water up and down and it's not magic, it comes from the spin moment of the planet.

另外的时间太阳轨道是不恒定要么,所以我们有闰秒时不时进行同步行星现实中的日历。在另一方面恒星时有没有这样愚蠢,所以我们漂远离它。再有就是相对论漂移。 GPS卫星移动如此之快,他们实际上有来弥补微小的时间扭曲。

Also the duration of a solar orbit isn't constant either, so we have leap seconds every now and then to synch the calendar with planetary reality. Sidereal time on the other hand has no such foolishness, so we drift away from it. Then there is relativistic drift. GPS satellites move so fast they actually have to compensate for slight time-warping.

这篇关于是否采取的TimeZoneInfo DST考虑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆