且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从 Mongodb 格式化 ISODate

更新时间:2021-11-09 22:14:54

JavaScript 的 Date 对象支持 ISO 日期格式,所以只要你能访问日期字符串,你可以这样做:

JavaScript's Date object supports the ISO date format, so as long as you have access to the date string, you can do something like this:

> foo = new Date("2012-07-14T01:00:00+01:00")
Sat, 14 Jul 2012 00:00:00 GMT
> foo.toTimeString()
'17:00:00 GMT-0700 (MST)'

如果您想要没有秒和时区的时间字符串,那么您可以调用 Date 对象上的 getHours() 和 getMinutes() 方法并自己格式化时间.

If you want the time string without the seconds and the time zone then you can call the getHours() and getMinutes() methods on the Date object and format the time yourself.