c#用时区解析日期时间 [英] c# parse date time with timezone
本文介绍了c#用时区解析日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何用时区解析日期时间.
How can we parse date time with time zone.
<TIMESTAMP_UTC>20180523160000</TIMESTAMP_UTC>
<TIMEZONE>UTC+8</TIMEZONE>
这应该转换为 2018-05-24 00:00:00.我尝试了几件事,但没有成功.我尝试了下面的命令,但它抛出了一个错误.
this should convert as in 2018-05-24 00:00:00. I tried couple of things but could not succeed. I tried the below command but it throws an error.
DateTime.ParseExact("20180523160000+08:00", "yyyyMMddHHmmssZhhmm", System.Globalization.CultureInfo.InvariantCulture)
你知道我们如何用 DateTime Parse 方法解析这个吗.
Do you know how we can parse this with DateTime Parse methods.
推荐答案
你需要使用DateTimeOffset.ParExact
var date = DateTimeOffset.ParseExact("20180523160000+08:00", "yyyyMMddHHmmsszzz", CultureInfo.InvariantCulture);
这篇关于c#用时区解析日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文