简体   繁体   中英

ConvertTimeFromUTC, Handling Australia DST

I have the following code, and I have aa customer in Canberra, Australia. They are typically UTC+10, however they are in DST right now so it is UTC+11. What is odd is when I run this code it is not accounting for DST, which I thought ConvertTimeFromUTC handles.

I am passing E. Australia Standard Time as the "timeZone" parameter. Any thoughts?

var myTimeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZone);
var currentDateTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, myTimeZone);
return currentDateTime;

Use "AUS Eastern Standard Time" for South-East Australia (New South Wales and Victoria) that uses DST, including Canberra, Melbourne, Sydney, etc.

Use "E. Australia Standard Time" for North-East Australia (Queensland) that does not have DST, including Brisbane, Lindeman, etc.

Otherwise, your code is correct.

Note that despite having the word "Standard" in the time zone IDs, .NET and Windows will correctly account for DST where applicable. There are no IDs that have the word "Daylight" in them.

For a complete list of time zones, use TimeZoneInfo.GetSystemTimeZones() and examine the .Id and .DisplayName properties of each. Alternatively, call tzutil.exe /l on the command line which will do the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM