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)
Use DateTimeOffset.Parse(string).UtcDateTime
.
来源:https://stackoverflow.com/questions/13254211/how-to-convert-string-to-datetime-as-utc-as-simple-as-that