1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 获取今天的日期(年月日时分秒) 获取今天昨天明天的日期

获取今天的日期(年月日时分秒) 获取今天昨天明天的日期

时间:2018-11-07 00:54:34

相关推荐

获取今天的日期(年月日时分秒) 获取今天昨天明天的日期

1、获取今天的日期(年月日时分秒)

getCurrentTime() {let yy = new Date().getFullYear();let mm = new Date().getMonth()+1;let dd = new Date().getDate();let hh = new Date().getHours();let mf = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes();let ss = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds();this.gettime = yy+'/'+mm+'/'+dd+' '+hh+':'+mf+':'+ss;console.log(this.gettime) }

2、获取昨天今天明天

mounted () {

console.log('昨天:', this.getDay(-1, 7200000))

console.log('今天:', this.getDay(0, 3600000))

console.log('明天:', this.getDay(1, 3600000))

console.log('一周后:', this.getDay(7, 7200000)

},

getDay (day, hours) {

var today = new Date()

var targetday = today.getTime() + 1000 * 60 * 60 * 24 * day + hours

today.setTime(targetday)

var tYear = today.getFullYear()

var tMonth = today.getMonth()

var tDate = today.getDate()

var getHours = today.getHours()

tMonth = this.doHandleMonth(tMonth + 1)

tDate = this.doHandleMonth(tDate)

return tYear + '-' + tMonth + '-' + tDate + '小时:' + getHours

},

doHandleMonth (month) {

var m = month

if (month.toString().length === 1) {

m = '0' + month

}

return m

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。