var now=new Date();//Mon Mar 15 2021 09:38:50 GMT+0800 (中国标准时间)
now.getFullYear();//年
now.getMonth();//月 0~11 代表月
now.getDate();//日
now.getDay();//星期
now.getHours();//时
now.getMinutes();//分
now.getSeconds();//秒
now.getTime();//时间戳 全世界统一
console.log(new Date(1615772517778))//时间戳转为时间
转换
now=new Date(1615772517778)
Mon Mar 15 2021 09:41:57 GMT+0800 (中国标准时间)
now.toLocaleString//注意,调用是一个方法,不是一个属性!
ƒ toLocaleString() { [native code] }
now.toLocaleString()
"2021/3/15 上午9:49:54"
now.toGMTString()
"Mon, 15 Mar 2021 01:49:54 GMT"