初始化
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
// timeStr表示时间 separator表示分隔符 type == yaer表示只返回年月日
|
||||
export function formatDate (timeStr = (new Date()), separator = '-', type){
|
||||
const date = new Date(timeStr)
|
||||
let yaer = date.getFullYear()
|
||||
let month = date.getMonth() + 1
|
||||
|
||||
let day = date.getDate()
|
||||
let hour = date.getHours()
|
||||
let minute = date.getMinutes()
|
||||
let second = date.getSeconds()
|
||||
if(type == 'year'){
|
||||
return yaer + separator + (month >= 10 ? month : ('0' + month)) + separator + (day >= 10 ? day : ('0' + day))
|
||||
}else {
|
||||
return yaer + separator + (month >= 10 ? month : ('0' + month)) + separator + (day >= 10 ? day : ('0' + day)) + ' ' + (hour >= 10 ? hour : ('0' + hour)) + ':' + (minute >= 10 ? minute : ('0' + minute)) + ':' + (second >= 10 ? second : ('0' + second))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user