assume I have this string : How can I convert it to DateTimeOffset object that will have UTC time - means -00:00 as Time Zone - even if I run it on machine on a specific ti
The accepted answer did not work for me. Using DateTimeOffset.Parse(string)
or DateTimeOffset.ParseExact(string)
with the .UtcDateTime
converter correctly changed the kind of the DateTime
to UTC, but also converted the time.
To get to a DateTime
that has the same time as the original string time, but in UTC use the following:
DateTime dt = DateTime.ParseExact(string, "yyyy-MM-ddTHH:mm:ss.fffffff",
CultureInfo.InvariantCulture);
dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc);