1.new Date() --- 获取当前时间

let now = new Date()

2.setHours与setDate等set方法设置时间

    let now = new Date()    
    now.setHours(10)

3.getTime() 获取时间戳

console.log(now.getTime()); //1589942787285

4.两个时间相减得到的是毫秒数

let now = new Date()
let now1 = new Date('2020-05-19 18:10:25')
console.log(now - now1); //59762285

5.打卡时用到的节流方法

    let endTime = new Date()
    let i = 0
    function sayHi(){
        i++
        if (new Date() - endTime <1000) return;
        console.log('hi',i);
        endTime = new Date()         
    }
    setInterval(() => {
      sayHi()  
    }, 500);

6.获取年月日时分秒星期

let yy = now.getFullYear()
let mm = now.getMonth()+1
let dd = now.getDate()
let hh = now.getHours()
let mi = now.getMinutes()
let sc = now.getSeconds()
let ww = '星期'+'日一二三四五六'[now.getDay()]