Say, if I have a database column that holds date/time in UTC time zone, I can read them into DateTime object in my ASP.NET web app written with C#. How do I convert them to a user provided time zone?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
To get Time Zones list in a system you can use TimeZoneInfo.GetSystemTimeZones() .It will give you a list of all available TimeZones for your system.
Because it is ReadOnlyCollection .Now You can bind this source with your DropDownCntrl .
This assumes that
time
has aKind = DateTimeKind.Utc
You could use
ConvertTimeFromUtc
:Or
TimeZoneInfo.ConvertTime
:You will probably want to check out the MSDN article on
TimeZoneInfo.ConvertTime
for the ins and outs of the method.It's probably worth reading all about converting between time zones on MSDN as well. It's more complex than you might think.