how to convert string to DateTime as UTC as simple

2020-02-28 02:19发布

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)

1条回答
聊天终结者
2楼-- · 2020-02-28 03:04

Use DateTimeOffset.Parse(string).UtcDateTime.

查看更多
登录 后发表回答