vue获取系统时间的前后几天(亲测可用)

export default {
data () {

return {

  cancelTime: '',

}

},
mounted () {
this.cancelTime = this.format(new Date(),day)
},
methods: {
format (date,day) {
var nd = date
nd = nd.valueOf()
nd = nd + day *24 * 60 * 60 * 1000
nd = new Date(nd)
var y = nd.getFullYear()// 获取年
var m = nd.getMonth() + 1// 获取月
var d = nd.getDate()// 获取天
var h = nd.getHours()// 获取小时
var f = nd.getMinutes()// 获取分钟
var s = nd.getSeconds()// 获取秒
if (m <= 9) m = ‘0’ + m
if (d <= 9) d = ‘0’ + d
if (h <= 9) h = ‘0’ + h
if (f <= 9) f = ‘0’ + f
if (s <= 9) s = ‘0’ + s
var cdate = y + ‘-’ + m + ‘-’ + d + ’ ’ + h + ‘:’ + f + ‘:’ + s
return cdate
}
}
}

你可能感兴趣的:(vue获取系统时间的前后几天(亲测可用))