user datetime setting as GMT, how to convert date to their localized setting?
问题 In my users setting I have a dropdown with all the GMT dates for the user to select. In c#, how would I convert a datetime stored in the database to their GMT time? The time stored in the database is the servers time. 回答1: For .NET 3.5+, you can store the system time zone identifier with the user (you can get those from TimeZoneInfo.GetSystemTimeZones ) and use TimeZoneInfo to convert between time zones: // In a User class that has a string timeZoneId field (for example) public DateTime