将中国标准时间转化为yyyy-MM-dd

// 将Thu May 12 2016 08:00:00 GMT+0800 (中国标准时间)转化为yyyy-MM-dd

parseTime (str) {

if ((str + '').indexOf('-') != -1) {

str = str.replace(new RegExp(/-/gm), '/')

}

let d = new Date(str)

let newDateYear = d.getFullYear()

let newDateMonth = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1)

let newDateDay = d.getDate() + '' < 10 ? '0' + d.getDate() + '' : d.getDate() + ''

return newDateYear + '-' + newDateMonth + '-' + newDateDay

},

猜你喜欢

转载自blog.csdn.net/localhost_1314/article/details/84784791