Assigning a Date
variable to another one will copy the reference to the same instance.(将Date
变量分配给另一个变量会将引用复制到同一实例。)
Date
instance?(如何实际克隆或复制Date
实例?)
ask by árvízt?r? tük?rfúrógép translate from so
Assigning a Date
variable to another one will copy the reference to the same instance.(将Date
变量分配给另一个变量会将引用复制到同一实例。)
Date
instance?(如何实际克隆或复制Date
实例?)
ask by árvízt?r? tük?rfúrógép translate from so
Use the Date object's getTime()
method, which returns the number of milliseconds since 1 January 1970 00:00:00 ( epoch time ):(使用Date对象的getTime()
方法,该方法返回自1970年1月1日00:00:00( 纪元时间 )以来的毫秒数:)
var date = new Date();
var copiedDate = new Date(date.getTime());
In Safari 4, you can also write:(在Safari 4中,您还可以编写:)
var date = new Date();
var copiedDate = new Date(date);
...but I'm not sure whether this works in other browsers.(...但是我不确定这是否可以在其他浏览器中使用。) (It seems to work in IE8).((它似乎在IE8中有效)。)