DateTime.ToLocalTime()冬季/夏季时间夏季、冬季、时间、DateTime

2023-09-04 09:07:01 作者:嫼液里夢潑泩媥簃//

我使用 DateTime.ToLocalTime()从UTC日期转换为本地时间。我的时区是GMT + 1(贝尔格莱德,布达佩斯,Lubjna ......),它设置正确,Windows设置(XP)。

I am using DateTime.ToLocalTime() to convert dates from UTC to local time. My time zone is GMT+1(Belgrade, Budapest, Lubjna...), it is set properly in Windows Settings (XP).

在我们的时区,我们改成冬令时夏令时间上周末,这意味着,我们设置回本地时间一小时。

Last weekend in our time zone we changed to winter time to summer time, it means, we set back local time by one hour.

在我ToLocalTime方法,从那个时刻的行为很奇怪。当我用它来转换日期是今年冬季时间更改后,它的伟大工程,是这样的:

As I see ToLocalTime method behaves strange from that moment. When I use it to convert dates that are after this winter time change, it works great, like this:

var utcDate2 = new DateTime(2011, 11, 2, 9, 0, 0,DateTimeKind.Utc);

utcDate1.ToLocalTime()值: 2011.11.02。 10:00:00 这是正确的。

伯特的时候我想约会此更改之前转换(如从夏时制的日期)它给回一个错误值是这样的:

Burt when I want to convert a date before this change (e.g. a date from summer time) it gives back a bad value like this:

var utcDate1 = new DateTime(2011, 10, 23, 9, 0, 0,DateTimeKind.Utc);

utcDate2.ToLocalTime()值: 2011.10.23。 10:00:00 这是不正确应该是2011.10.23。 11:00:00

utcDate2.ToLocalTime() value is: 2011.10.23. 10:00:00 it is incorrect It should be 2011.10.23. 11:00:00

我该怎么做才能得到正确的价值观?我应该如何使用ToLocalTime也调整冬季/夏季时间?

What should I do to get correct values? How should I use ToLocalTime that also adjust winter/summer time?

推荐答案

的 http://msdn.microsoft.com/en-us/library/system.datetime.tolocaltime.aspx

在Windows XP系统中,ToLocalTime方法只承认   目前的调整规则从UTC转换为本地时间。作为一个   结果,转换为当前的调整规则之前时期   生效可能无法准确反映的是UTC的区别   与本地时间

On Windows XP systems, the ToLocalTime method recognizes only the current adjustment rule when converting from UTC to local time. As a result, conversions for periods before the current adjustment rule came into effect may not accurately reflect the difference between UTC and local time.

所以,你将不得不寻找另一种方式来看着办吧。

So you will have to find another way to figure it out.

 
精彩推荐
图片推荐