ISO 8601中的日期时间与javascript中的UTC格式有什么区别? [英] What's the difference between datetime in ISO 8601 and UTC formats in javascript?

查看:317
本文介绍了ISO 8601中的日期时间与javascript中的UTC格式有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在javascript中选择了一些日期和时间,然后想将它存储在服务器(.NET)上。日期应该是从当前时刻开始的(因此它们不会在1970年之前)。
在这里阅读了有关SO的主题我了解到最好将日期存储为字符串,人们建议使用 Date.prototype.toISOString() Date.prototype.toUTCString()
我读过IE 7中没有提供 toISOString()。我想知道其他差异,何时我应该选择一个或另一个功能。

I pick some date and time in javascript and then want to store it on server (.NET). Dates are supposed to be in future from the current moment (so they won't be before 1970). Having read topics here on SO I learnt it's better to store date as a string and people suggest using Date.prototype.toISOString() or Date.prototype.toUTCString(). I've read that toISOString() is not available in IE 7. And I'd like to know other differences, when I should choose one or another function.

谢谢!

推荐答案

两者都不同。 ISO 是标准格式时间。 UTC 是世界规定时钟和时间的主要时间标准。 ISO还支持 ms 格式。

Both are different. ISO is standard format time. UTC is the primary time standard by which the world regulates clocks and time. ISO also supports ms in its format.

因此,如果要将数据发送到服务器,请发送ISO ,因为ISO是标准格式:

So if you want to send data to the server, send the ISO, because ISO is the standard format:

var date = new Date();
sendDate(date.toISOString());

您还可以在IE7中使用 toISOString a href =https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString#Polyfill =noreferrer> polyfill 。

You can also use toISOString in IE7 polyfill.

这篇关于ISO 8601中的日期时间与javascript中的UTC格式有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆