I am storing information in a database and setting my POCO’s property to DateTime.Now.
When this value is displayed it is appearing as the PST time. I would like it to to display as GMT time.
Do I do something like this to display/store it or is there a better way?
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("GMT");
var GMTTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now, tz));
Also it needs to consider Daylight Savings as UK changes its clocks at different times in the year than USA:
UPDATE: I have found that in the TimeZone setting you can pass either GMT Standard Time or Greenwich Mean Time, the first taking into account DST
Store it as UTC. It’s designed for universal timezone-independent time.
Whether a given
DateTimeis already UTC or local time is determined byDateTime.Kind. You have to keep this in mind when serializing/deserializingDateTimevalues (e.g from a database) because this information is often not stored and when you get yourDateTimeback, it will most of the time have the valueDateTimeKind.Unspecified, which may cause issues with conversion methods. I just make sure to forceDateTimeKind.Utcwhen I load something in from a persistent data store.