ConvertTimeFromUTC, Handling Australia DST

旧巷老猫 提交于 2020-01-11 11:22:09

问题


I have the following code, and I have a a 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;

回答1:


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.



来源:https://stackoverflow.com/questions/48154602/converttimefromutc-handling-australia-dst

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!