user1471724
user1471724

Reputation: 13

Two timezones are UTC-7 but with different datetime appearance

I am working on timezones problems. I have a datetime here 2015-8-24 14:00:00 in UTC format. I need to convert it to timezone (UTC-7:00) Arizona and (UTC-7:00) US Mountain Time (USA & Canada).

I think that after converting it, the times should be the same, but am wrong by below code:

var utc = DateTime.Parse("2015-08-24 14:00:00") ;

//(UTC-7:00)Arzona
var _timeZone = TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
DateTime result = TimeZoneInfo.ConvertTime(utc, TimeZoneInfo.Utc, _timeZone);
var convertedResult =  DateTime.SpecifyKind(result, DateTimeKind.Local);

// shows 2015-08-24 8:00:00 AM 
Console.WriteLine(convertedResult.ToString("yyyy-MM-dd hh:mm:ss"));


// (UTC-7:00) US Mountain Time (USA & Canada)
var _timeZoneEx = TimeZoneInfo.FindSystemTimeZoneById("US Mountain Standard Time");
DateTime resultex = TimeZoneInfo.ConvertTime(utc, TimeZoneInfo.Utc, _timeZoneEx);
var convertedResultex = DateTime.SpecifyKind(resultex, DateTimeKind.Local);

// shows 2015-08-24 7:00:00 AM 
Console.WriteLine(convertedResultex.ToString("yyyy-MM-dd hh:mm:ss"));

See the result? It's different. Expect the reference. thx.

Upvotes: 1

Views: 258

Answers (1)

marc_s
marc_s

Reputation: 754538

If you look at the SupportsDaylightSavingTime property, it should become obvious - Mountain Standard Time does support it, while US Mountain Standard Time does NOT support it (hence the one hour difference).

Upvotes: 1

Related Questions