时间日期处理

js对时间戳处理成年月日时分秒 + yyyy.mm.dd

1
2
3
4
5
6
7
8
9
10
11
12
13
export function timeToDate(time, type = 'yyyy.mm.dd') {
let date = new Date(time)
let day = date.getDate()
if ((day + '').length < 2) {
day = '0' + day
}
if (type === 'yyyy.mm.dd'){
return `${date.getFullYear()}.${date.getMonth() + 1}.${day}`
} else if (type === 'yyyy.mm.dd hh:mm') {
let minutes = (date.getMinutes() + '').length <= 1 ? ('0' + date.getMinutes()) : date.getMinutes()
return `${date.getFullYear()}.${date.getMonth() + 1}.${day} ${date.getHours()}:${minutes}`
}
}

Powered by Hexo and Hexo-theme-hiker

Copyright © 2013 - 2024 HL's Blog All Rights Reserved.

UV : | PV :