admin管理员组文章数量:1296401
I can create a JavaScript date object with:
var d=new Date('2012-08-07T07:47:46Z');
document.write(d);
This will write the date using the browser's time zone. But I should be able to do (no 'Z'):
var d=new Date('2012-08-07T07:47:46');
document.write(d);
This returns the same as above, but according to the ISO8601 standard, a string without a timezone (e.g. +01:00) and without 'Z', the date should be considered in the local time zone. So the second example above should write the datetime as 7:47am.
I am getting a datetime string from a server and I want to display exactly that datetime. Any ideas?
I can create a JavaScript date object with:
var d=new Date('2012-08-07T07:47:46Z');
document.write(d);
This will write the date using the browser's time zone. But I should be able to do (no 'Z'):
var d=new Date('2012-08-07T07:47:46');
document.write(d);
This returns the same as above, but according to the ISO8601 standard, a string without a timezone (e.g. +01:00) and without 'Z', the date should be considered in the local time zone. So the second example above should write the datetime as 7:47am.
I am getting a datetime string from a server and I want to display exactly that datetime. Any ideas?
Share edited Apr 15, 2019 at 14:57 Alexander Abakumov 14.6k16 gold badges97 silver badges133 bronze badges asked Aug 7, 2012 at 10:12 bobdevbobdev 1532 gold badges2 silver badges7 bronze badges 01 Answer
Reset to default 6I found this script works well. It extends the Date.parse method.
https://github./csnover/js-iso8601/
Date.parse('2012-08-07T07:47:46');
It doesn't work on the new Date()
constructor however.
本文标签: javascriptParse JSON (ISO8601) date stringStack Overflow
版权声明:本文标题:javascript - Parse JSON (ISO8601) date string - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741632753a2389462.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论