将isodate转换为数值 [英] Converting isodate to numerical value
本文介绍了将isodate转换为数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在执行测试以确保我正确地获取了日期.
I am performing tests to ensure I'm getting the dates correctly.
我当前的测试是:选择mongodb ISODate格式的日期并将其转换为数值(自1970年以来为毫秒),反之亦然
My current tests are: pick a date in mongodb ISODate format and transform it to the numerical value (milliseconds since 1970) and vice versa
示例:
var date_test = ISODate ("2013-07-26T22:35:40.373Z")
此日期的数值是多少?哪个命令用于获取此信息?
What is the numeric value of this date? Which command is used to get this?
推荐答案
只需调用 getTime()
方法,您将获得自1970/01/01以来的毫秒数
Simply call the getTime()
method, and you get the milliseconds since 1970/01/01
> var date_test = ISODate ("2013-07-26T22:35:40.373Z")
> date_test.getTime()
1374878140373
要将毫秒转换回日期,请构造一个新的日期对象:
to convert milliseconds into date back, construct a new date object:
> new Date(1374878140373)
ISODate("2013-07-26T22:35:40.373Z")
这篇关于将isodate转换为数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文