Warm tip: This article is reproduced from serverfault.com, please click

how to convert string to DateTime as UTC as simple as that

发布于 2012-11-06 15:28:49

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 timezone?

Assume String: "2012-10-08T04:50:12.0000000"

Convert.ToDateTime("2012-10-08T04:50:12.0000000" + "Z");

--> DateTime d = {10/8/2012 6:50:12 AM} and I want it to be DateTime d = {10/8/2012 4:50:12 AM} as if it will understand I want the date as simple as it comes (BTW - my machine is in timezone +02:00)

Questioner
user1025852
Viewed
0
Knaģis 2012-11-06 23:32:07

Use DateTimeOffset.Parse(string).UtcDateTime.