编程语言
首页 > 编程语言> > JavaScript——Date日期对象

JavaScript——Date日期对象

作者:互联网

  标准对象

typeof 123
"number"
typeof '123' "string"
typeof true "boolean"
typeof NaN "number"
typeof [] "object"
typeof {} "object"
typeof Math.abs "function"
typeof undefined "undefined"

 

  基本使用

  var now=new Date();    //中国标准时间
  now.getFullYear();   //年
  now.getMonth();    //月    0~11代表月份
  now.getDate();    //日
  now.getDay();     //星期几
  now.getHours();   //时
  now.getMinutes();  //分
  now.getSeconds();  //秒

  now.getTime();    //时间戳   全世界统一   1970 1.1 0:00:00 毫秒数

  console.log(new Date(1620735319811))   //时间戳转换为时间

 

   转换

now=new Date(1620735319811)
Tue May 11 2021 20:15:19 GMT+0800 (中国标准时间)

now.toLocaleDateString      //注意:调用是一个方式,不是一个属性
ƒ toLocaleDateString() { [native code] }

now.toLocaleDateString()
"2021/5/11"

now.toGMTString()
"Tue, 11 May 2021 12:15:19 GMT"

 

标签:11,JavaScript,toLocaleDateString,日期,typeof,Date,new,now
来源: https://www.cnblogs.com/clblogs/p/14757211.html