获取日期格式
functionkeepDouble(number) {
number=Number(number)
if(number>=10) {
returnnumber
}
return'0'+number
}
exportfunctiongetDate(date,format) {
if(!date) {
return
}
varY,M,D,h,m,s
if(typeof(date) ==='object') {
Y=date.getFullYear()
M=keepDouble(date.getMonth() +1)
D=keepDouble(date.getDate())
h=keepDouble(date.getHours())
m=keepDouble(date.getMinutes())
s=keepDouble(date.getSeconds())
}else{
if(date.indexOf(' ') === -1) {
return
}
vartime1=date.split(' ')[0]
vartime2=date.split(' ')[1]
Y=time1.split('-')[0]
M=keepDouble(time1.split('-')[1])
D=keepDouble(time1.split('-')[2])
h=keepDouble(time2.split(':')[0])
m=keepDouble(time2.split(':')[1])
s=keepDouble(time2.split(':')[2])
}
format=format.replace('Y',Y)
format=format.replace('M',M)
format=format.replace('D',D)
format=format.replace('h',h)
format=format.replace('m',m)
format=format.replace('s',s)
format=format.replace('Y',Y)
returnformat
}
网友评论