本文共 758 字,大约阅读时间需要 2 分钟。
一、获取当前日期:
mounted () { this.getTime() },
getTime () { // new Date() new一个data对象,当前日期和时间 // toLocaleString() 方法可根据本地时间把 Date 对象转换为字符串,并返回结果。 this.nowtime = new Date().toLocaleString() console.log('nowtime: ', this.nowtime) },
控制台打印:
二、获取当前日期以及前七天日期:
mounted () { this.getTime() this.aa() },
aa () { var myDate = new Date() // 获取今天日期 myDate.setDate(myDate.getDate() - 6) var dateArray = [] var dateTemp var flag = 1 for (var i = 0; i < 7; i++) { dateTemp = (myDate.getMonth() + 1) + '-' + myDate.getDate() dateArray.push(dateTemp) myDate.setDate(myDate.getDate() + flag) } console.log('123456+', dateArray) },
控制台打印:
转载地址:http://fmlbi.baihongyu.com/