17 lines
672 B
TypeScript
17 lines
672 B
TypeScript
export function formatDate(time:Date|string,separator='-'){
|
|
time=new Date(time);
|
|
let year=time.getFullYear(),
|
|
month=time.getMonth()+ 1,
|
|
date=time.getDate();
|
|
return year+separator+(month<10?'0'+month:month)+separator+(date<10?'0'+date:date);
|
|
}
|
|
|
|
//时间格式化
|
|
export function formatTime(time:Date,separator1='-',seperator2=':'){
|
|
time=new Date(time);
|
|
let date=formatDate(time,separator1),
|
|
hours=time.getHours(),
|
|
minutes=time.getMinutes(),
|
|
seconds=time.getSeconds();
|
|
return date+' '+(hours<10?'0'+hours:hours)+seperator2+(minutes<10?'0'+minutes:minutes)+seperator2+(seconds<10?'0'+seconds:seconds);
|
|
} |