基本引用类型-Date
1.let n = new Date()
Date()不传参表示返回当前时间,传参必须传入其毫秒表示,基于参数创建日期对象。
Date.now()表示当前日期和时间的毫秒数。
2.toLocaleString(),toString(),valueOf();前两者返回时间的字符串表示,后者返回毫秒表示。
3.Date.parse() 和 Date.UTC(),把时间用毫秒表示,只是参数的形式不一样。
Date.parse("May 23,2019") // 还有其它形式
Date.UTC(2005,4,5,17,5,55) // GMT时间2005年5月5日下午5点5分55秒
4.时间的格式化 ,使用getFullYear(),getMonth(),getDate()等方法。
function timefilters (val) { if (val === null || val === '') { return '' } else { // val 为表格内取到的后台时间 const d = new Date(val) const month = d.getMonth() + 1 < 10 ? '0' + (d.getMonth() + 1) : d.getMonth() + 1 const day = d.getDate() < 10 ? '0' + d.getDate() : d.getDate() const times = d.getFullYear() + '/' + month + '/' + day return times } }

浙公网安备 33010602011771号