什么是JavaScript的默认日期格式?
这种格式的名称是什么?
Wed Jul 06 2022 14:42:13 GMT-0400 (Eastern Daylight Time)
此格式是从new Date()
输出“独立于输入格式”的默认格式。
- source- https://www.www.w3schools.coms.coms.coms.coms.coms.com/js/js/js_date_date_formats.asp w3schools解释了格式,但未提及它的名字在进入其他ISO格式类型之前。
如何使用Moment.js将日期变成该格式?
- 示例:
2022-07-15T00:00:00.000Z
或2015-03-25
console.log(moment(new Date()).toISOString());
// 2022-07-06T19:08:36.670Z
console.log(moment(new Date()).toString());
// Wed Jul 06 2022 15:08:36 GMT-0400
console.log(new Date());
// Wed Jul 06 2022 15:08:36 GMT-0400 (Eastern Daylight Time)
console.log(new Date().toString());
// Wed Jul 06 2022 15:08:36 GMT-0400 (Eastern Daylight Time)
您可以看到该moment(new Date())。
和moment(new Date())。toString()
不要与默认JS格式相同的格式输出。
moment(new Date())。toString()
是接近的,但是仍然缺少(东部日光时间)
,是默认值的一部分。
What is the name of this format?
Wed Jul 06 2022 14:42:13 GMT-0400 (Eastern Daylight Time)
This format is the default format that is output "Independent of input format" from new Date()
.
- source - https://www.w3schools.com/js/js_date_formats.asp w3schools explains the format but fails to mention what it's called before getting into other ISO format types.
How do you turn a date into that format using Moment.js?
- Example:
2022-07-15T00:00:00.000Z
or2015-03-25
console.log(moment(new Date()).toISOString());
// 2022-07-06T19:08:36.670Z
console.log(moment(new Date()).toString());
// Wed Jul 06 2022 15:08:36 GMT-0400
console.log(new Date());
// Wed Jul 06 2022 15:08:36 GMT-0400 (Eastern Daylight Time)
console.log(new Date().toString());
// Wed Jul 06 2022 15:08:36 GMT-0400 (Eastern Daylight Time)
You can see that moment(new Date()).toISOString()
and moment(new Date()).toString()
DO NOT output that same format as the default JS format.
moment(new Date()).toString()
is close, but is still missing the(Eastern Daylight Time)
which is part of the default.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它不是ISO,它是ECMA-262中指定的格式,在此处阅读更多: https://developer.mozilla.org/en-us/docs/web/javascript/reference/reference/global_objects/date/tostring
将其转换为ISO使用
date> date.to.toisstring()代码>
BTW。不要使用
w3schools.com
本网站有重大错误MOMM(new Date())。toisostring()
2015-03-25
:moment(new Date())。格式('yyyy-mm -dd')
moment(new Date())。todate()。toString()
ps ps我将考虑使用其他库作为MONM.JS。更新了,但是如果您别无选择,就可以了。
It's not ISO, it's a format specified in ECMA-262, read more here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString
To convert it to ISO use
date.toISOString()
Btw. don't use
w3schools.com
this website has major errorsmoment(new Date()).toISOString()
2015-03-25
:moment(new Date()).format('yyyy-MM-dd')
moment(new Date()).toDate().toString()
P.S. I would consider using a different library as moment.js isn't getting updates anymore, but if you don't have a choice it's fine.
答案:
console.log(Moment(new Date())。todate());
,它比应该更难找到。
奖励:
Answer:
console.log(moment(new Date()).toDate());
That was way harder to find than it should have been.
Bonus: