定义日期:

Date 对象用于处理日期和时间。

可以通过 new 关键词来定义 Date 对象。以下代码定义了名为 myDate 的 Date 对象:

var myDate=new Date()

注释:Date 对象自动使用当前的日期和时间作为其初始值。

var myDate=new Date(2013-1-10)


Javascript 获取当前时间戳(毫秒级别):

第一种方法:
var timestamp1 = Date.parse( new Date());

结果:1372751992000

第二种方法:
var timestamp2 = ( new Date()).valueOf();

结果:1372751992066

第三种方法:
var timestamp3 = new Date().getTime();

结果:1372751992066

alert(timestamp1);
alert(timestamp2);
alert(timestamp3);

备注:第一种获取的时间戳是把毫秒改成000显示,第二种和第三种是获取了当前毫秒的时间戳。 

 

相关文章:

  • 2021-12-29
  • 2022-12-23
  • 2021-11-18
猜你喜欢
  • 2022-02-15
  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
  • 2022-01-09
相关资源
相似解决方案