问题描述
运行此jsfiddle:Chrome上的, FF和IE,你会得到:
Run this jsfiddle: http://jsfiddle.net/E9gq9/7/ on Chrome, FF, and IE and you get:
Chrome:
Firefox:
IE:
Safari:
似乎没有说明如何解释一个没有尾随Z的字符串。
ISO 8601 does not appear to say how a string without a trailing Z should be interpreted.
我们的服务器ASP.NET MVC4)将UTC时间从我们的数据库中拖出为 DateTime
,只需将其填充到JSON中即可。正如你所看到的,因为我们在浏览器上的结果不一致。
Our server (ASP.NET MVC4) is pulling UTC times out of our database as DateTime
s and simply stuffing them in JSON. As you can see because of this we are getting inconsistent results on the browser.
我们应该在服务器端附加Z吗?
Should we just append Z to them on the server side?
推荐答案
哪个是正确的,它是Firefox和IE的错误。
Which is correct, it's Firefox and IE that are getting it wrong.
虽然您链接的文章确实说明了当没有 Z
(如果没有给出UTC时间表示的UTC关系信息,这意味着什么时间假定是在当地时间。),更重要的是很清楚地表明,没有时区信息意味着 Z
:
While the article you linked does indeed say what it means when there's no Z
("If no UTC relation information is given with a time representation, the time is assumed to be in local time."), the more important thing is that the ECMAScript5 specification says quite clearly that no timezone information means Z
:
是的,我会可能确保字符串有一个 Z
,因为这似乎给你一致的结果。
Yes, I would probably ensure the string has a Z
on it, as that seems to give you consistent results.
这篇关于Chrome将没有Z的ISO时间解释为UTC; C#问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!