2020-02-11T12:24:18.000+0000 转化成正常格式
function renderTime(date) {
var dateee = new Date(date).toJSON();
return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
}
new Date()转UTC格式:
new Date().toISOString()
new Date() 转时间戳:
new Date(中国标准时间).getTime()
UTC时间转new Date()
d = new Date(UTC)
new Date() /中国标准时间=> yyyy-mm-dd hh:ss:mm
formatDate(date) {
const d = new Date(date)
const yy = d.getFullYear()
const mon = this.addZero(d.getMonth() + 1)
const dd = this.addZero(d.getDate())
const hh = this.addZero(d.getHours())
const min = this.addZero(d.getMinutes())
const ss = this.addZero(d.getSeconds())
return `${yy}-${mon}-${dd} ${hh}:${min}:${ss}`
},
addZero(i) {
if (i < 10) {
i = `0${i}`
}
return i
},
// 时间格式转换 YYYY-MM-DD
export function getDayTimer (data) {
var date = new Date(data)
var y = date.getFullYear()
var m = date.getMonth() + 1
m = m < 10 ? ('0' + m) : m
var d = date.getDate()
d = d < 10 ? ('0' + d) : d
var currentdate = y + '-' + m + '-' + d
return currentdate
}
// 时间格式转换 YYYY-MM-DD hh:mm:ss
export function getDayTimer (data) {
var date = new Date(data)
var y = date.getFullYear()
var m = date.getMonth() + 1
m = m < 10 ? ('0' + m) : m
var d = date.getDate()
d = d < 10 ? ('0' + d) : d
var currentdate = y + '-' + m + '-' + d;
var hh = date.getHours()
hh = hh < 10 ? ('0' + hh) : hh
var mm = date.getMinutes()
mm = mm < 10 ? ('0' + mm) : mm
var ss = date.getSeconds()
ss = ss < 10 ? ('0' + ss) : ss
var time = hh + ':' + mm + ':' + ss;
return currentdate + " " + time
}

博客主要围绕JavaScript中日期格式转换展开,介绍了将2020 - 02 - 11T12:24:18.000+0000转化为正常格式,以及new Date()转UTC格式、转时间戳,UTC时间转new Date(),还有将中国标准时间转换为yyyy - mm - dd hh:ss:mm格式等内容。
1万+

被折叠的 条评论
为什么被折叠?



