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

c#-如何将字符串转换为像UTC这样的DateTime就这么简单

(c# - how to convert string to DateTime as UTC as simple as that)

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

假设我有这个字符串:即使我在特定时区的计算机上运行它,也如何将其转换为具有UTC时间的DateTimeOffset对象-意味着-00:00作为时区?

假设字符串:“ 2012-10-08T04:50:12.0000000”

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

-> DateTime d = {10/8/2012 6:50:12 AM},我希望它是 DateTime d = {10/8/2012 4:50:12 AM} ,好像它将理解我想要日期如此简单(顺便说一句-我的机器在时区+02:00)

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

使用DateTimeOffset.Parse(string).UtcDateTime