The following code:
var dateTime1 = DateTime.Now;
var str = dateTime1.ToString("dd-MMM-yyyy HH:mm:sszzz");
Console.WriteLine(str);
var dateTime2 = dateTime1.ToUniversalTime();
str = dateTime2.ToString("dd-MMM-yyyy HH:mm:ss");
Console.WriteLine(str);
var dateTime3 = TimeZoneInfo.ConvertTimeFromUtc(dateTime2, TimeZoneInfo.Local);
str = dateTime3.ToString("dd-MMM-yyyy HH:mm:sszzz");
Console.WriteLine(str);
prints as excepted:
18-Feb-2010 09:07:06-05:00
18-Feb-2010 14:07:06
18-Feb-2010 09:07:06-05:00
On the other hand the code:
var dateTime1 = DateTime.ParseExact("20090615013505-0400", "yyyyMMddHHmmsszzz",null);
var str = dateTime1.ToString("dd-MMM-yyyy HH:mm:sszzz");
Console.WriteLine(str);
var dateTime2 = dateTime1.ToUniversalTime();
str = dateTime2.ToString("dd-MMM-yyyy HH:mm:ss");
Console.WriteLine(str);
var dateTime3 = TimeZoneInfo.ConvertTimeFromUtc(dateTime2, TimeZoneInfo.Local);
str = dateTime3.ToString("dd-MMM-yyyy HH:mm:sszzz");
Console.WriteLine(str);
prints this:
15-Jun-2009 01:35:05-04:00
15-Jun-2009 05:35:05
15-Jun-2009 01:35:05-04:00
I expected the last line to be 15-Jun-2009 00:35-05:00 since the local time zone is GMT-05:00.
What am I missing here?