时间对象
创建对象的过程就是实例化
//获得当前时间(小括号为空是系统当时的时间)(Date()D必须大写)
let date=new Date()
let date = new Date("2018-02-23 22:22:22");自定义时间
▲时间对象的常用方法
//创建对象
let date = new Date();
//获取四位年份
console.log(date.getFullYear());
//获得月份(取值为0-11)
console.log(date.getMonth());
//获取月份中的某一天
console.log(date.getDate());
//获取星期(取值为0-6)
console.log(date.getDay());
//获取小时(取值为0-23)
console.log(date.getHours());
//获取分钟
console.log(date.getMinutes());
//获取秒
console.log(date.getSeconds());
时间戳
是指1970年01月01日00时00分00秒到现在的毫秒数
▲获得时间戳的方法
1.对象方法:
getTime()
用法:let date = new Date();
console.log(date.getTime());
2.+new Date()
用法: console.log(+new Date());
console.log(+new Date());
3.Date.now()
——只能获得当前时间的时间戳
★★前两种方法可以计算指定时间