JSON.NET Parses +00:00 timezone as local times, but Z as UTC

别说谁变了你拦得住时间么 提交于 2019-12-06 16:42:27

DateTime only distinguishes between UTC and Local (and Unknown). This causes all manner of problems considering that two different Local times could of course be local to two different zones, and a Local time could indeed be a UTC time if it's in a time zone that uses UTC (e.g. Iceland all the year long, or Ireland during the Winter). Because of this a DateTime could be Local and have a time difference to UTC of zero.

ISO 8601 on the otherhand (much more sensibly) either includes timezone information along with the date and/or time, or it doesn't.

There's no perfect way to roundtrip between the two, so considering Z to mean UTC and +00:00 to mean Local (but the sort of local that is identical to UTC) is an imperfect compromise to this situation, made a bit less imperfect by providing a DateTimeZoneHandling so that people can adjust from that compromise.

Using DateTimeOffset instead of DateTime is another way of dealing with the mismatch between DateTime and a combination of date, time and offset.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!