[英]Why is my Date object returning the current date?
I have my time since epoch stored as a number: 1444749469000. However, when I try to convert it to a Date object, using Date(1444749469000)
, it just gives me the current date instead of the one it should be (around Tue Oct 13 2015). 从纪元起,我的时间已存储为数字:1444749469000。但是,当我尝试使用
Date(1444749469000)
将其转换为Date对象时,它只是给出了当前日期,而不是应该显示的当前日期(大约十月10日) 2015年13月)。
> Date(1444749469000)
"Tue Apr 12 2016 09:28:30 GMT-0700 (PDT)"
You need a new
before the Date
because Date
is a constructor: 您需要在
Date
之前输入一个new
,因为Date
是构造函数:
var d = new Date(1444749469000) alert(d);
Because when you call Date
as a function, it will return a string of current date and ignore the given value. 因为当您将
Date
用作函数时,它将返回当前日期的字符串,并忽略给定的值。 In order to retrieve the Date
object, you must initialize the Date
constructor with keyword new
. 为了检索
Date
对象,必须使用关键字new
初始化Date
构造函数。
var now = Date(1444749469000);
var date = new Date(1444749469000);
console.log(typeof now); //string
console.log(typeof date); //object
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.