如何将字符串转换为像UTC这样的DateTime就这么简单 [英] how to convert string to DateTime as UTC as simple as that
问题描述
假设我有以下字符串:
如何将其转换为具有UTC时间的DateTimeOffset对象-意味着-00:00作为时区-即使我在特定时区上在计算机上运行它?
假设字符串:
2012-10-08T04:50:12.0000000
Convert.ToDateTime( 2012-10-08T04:50:12.0000000 + Z);
-> DateTime d = {2012/10/8 6:50:12}
,我希望它成为
DateTime d = {10/8/2012 4:50:12 AM} ,好像可以理解我想要的日期一样简单(
-我的机器所在的时区为+02: 00)
使用 DateTimeOffset.Parse(string).UtcDateTime
。
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
.
这篇关于如何将字符串转换为像UTC这样的DateTime就这么简单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!