You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Example Localhost
DateTimeOffset TimeZoneInfoConvert = System.TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse("10/9/2018 8:00:00 AM"), System.TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"));
Correct result: 10/9/2018 10:00:00 AM +02:00
Server
DateTimeOffset TimeZoneInfoConvert = System.TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse("10/9/2018 8:00:00 AM"), System.TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"));
Wrong result: 10/9/2018 10:00:00 AM +00:00
The text was updated successfully, but these errors were encountered:
ConvertTimeFromUtc returns a DateTime rather than a DateTimeOffset. Given no DateTimeStyles, the parse result will have a kind of Unspecified. The implicit conversion to a DateTimeOffset from a DateTime of kind Local or Unspecified uses your local time zone offset. It seems that your server's time zone is UTC while your local machine's time zone is W. Europe Standard Time. You could confirm that by examining TimeZoneInfo.Local.BaseUtcOffset on both systems.
To be clear, almost certainly what you want to be doing is something similar to:
// Because that date format is culture specific!varparsedUtc= DateTimeOffset.Parse("2018-10-09 08:00:00", CultureInfo.InvariantCulture);DateTimeOffsetTimeZoneInfoConvert= TimeZoneInfo.ConvertTimeBySystemTimeZoneId(parsedUtc,"W. Europe Standard Time");
...or you can use NodaTime, and use the appropriate domain types.
We want to convert time.
Example
Localhost
DateTimeOffset TimeZoneInfoConvert = System.TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse("10/9/2018 8:00:00 AM"), System.TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"));
Correct result: 10/9/2018 10:00:00 AM +02:00
Server
DateTimeOffset TimeZoneInfoConvert = System.TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse("10/9/2018 8:00:00 AM"), System.TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"));
Wrong result: 10/9/2018 10:00:00 AM +00:00
The text was updated successfully, but these errors were encountered: