Convert DateTimeOffset to DateTime and add offset to this DateTime

Alex picture Alex · Jan 15, 2015 · Viewed 44.4k times · Source

I have DateTimeOffset:

    DateTimeOffset myDTO = DateTimeOffset.ParseExact(
                      "2015/01/15 17:37:00 -0500", "yyyy/MM/dd HH:mm:ss zzz", 
                      CultureInfo.InvariantCulture); 
Console.WriteLine(myDTO);

Result => "1/15/2015 17:37:00 -05:00"

How convert to DateTime and add this offset "-0500" in the resulted DateTime

Desired result => "1/15/2015 22:37:00"

Answer

Tim Schmelter picture Tim Schmelter · Jan 15, 2015

Use DateTimeOffset.UtcDateTime:

DateTime utc = myDTO.UtcDateTime; // 01/15/2015 22:37:00