poniedziałek, 20 listopada 2017

Convert string with UTC DateTime to DateTime with keeping UTC value

Input string:

string dateTime = "2010-01-01T19:00:00.000000Z"

When we use:

DateTime date = Convert.ToDateTime(dateTime);

we get invalid date:

{01/01/2010 20:00:00}


To get correct date in UTC time we need to use

DateTime date = DateTimeOffset.Parse(dateTime).UtcDateTime;

Brak komentarzy:

Prześlij komentarz