开发者

How to get the TimeZone for metazones by using FindSystemTimeZoneById?

I was given the TzID (Olson tzid format Exp: "Europe/Copenhagen"). After that, i tried to do the timezone conversion for certain DateTime from that timezone (different with server local time zone) to UTC by using c# TimeZonInfo class.

I was wondering why window's timezone id only have about 100 whereas the timezone id for Olson tz database have about 405 tz id. Lets say for time zone "Europe/Copenhagen", i have no idea how to use the FindSystemTimeZonebyID to get the time zone info for this time zone (It was listed in metazones in the Olson ID to windows ID convertion table). Anyone ex开发者_如何学运维perienced in this? Please help me.


From MSDN:

FindSystemTimeZoneById tries to match id to the subkey names of the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones branch of the registry under Windows XP and Windows Vista. This branch does not necessarily contain a comprehensive list of time zone identifiers.

Based on the table you link to, you want to pass in the string Europe_Central, since it is the Windows version of the Olson "Europe/Copenhagen". (Note that according to the MSDN docs, it is not case sensitive.) If that doesn't work, you should check your registry to ensure the Europe_Central entry exists.

For more on the Olson tz database and how it defines timezones, see wikipedia.


Update 1:

My registry (Vista) has it listed as Central Europe Standard Time, which is the string I'd need to pass in as the parameter, do you have a similar entry?

If that entry isn't in your Registry, you can create it yourself using info from here, though it looks like you'd have to construct the rules for summer time (see the link).

You could also try using a DateTimeOffset with a DateTime holding the local server time and passing in a TimeSpan of +1 hour (CET).

Depending on what you're trying to do, you can also just subtract one hour from the CET time to get UTC. (Though that won't work once Central Europe Summer Time takes effect; then you'll need to subtract two hours.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜