export default {
name: "TestTwo",
data() {
return {
startTime: this.GetDate(2),
}
},
created() {
this.SetDate(3)
this.showTime()
},
methods: {
//获取当前时间
showTime() {
const d = new Date()
// console.log(new Date().toString().padStart(2,'0'),'test')
// new Date().getDate().toString().padStart(2,'0')输出格式为02
// padStart()要与字符串类型配合使用
console.log('First', d.getFullYear() + '-'
+ (d.getMonth() + 1) + '-' + d.getDate().toString().padStart(2, '0'))
},
SetDate(num) {
const d = new Date()
let date2 = new Date(d)
date2.setDate(d.getDate() + num)
// console.log(date2.setDate(d.getDate()+num))输出为毫秒数
//num是正数表示之后的时间,num是负数表示之前的是时间,0表示今天
let TimeTwo = date2.getFullYear() + '-' + (date2.getMonth() + 1) + '-' + date2.getDate().toString().padStart(2, '0')
console.log(TimeTwo)
}
}
}