perf[utils]: refine parseTime function

This commit is contained in:
Pan 2019-01-30 14:12:32 +08:00
parent 6e6aa1dc10
commit 1204075849
1 changed files with 6 additions and 1 deletions

View File

@ -11,7 +11,12 @@ export function parseTime(time, cFormat) {
if (typeof time === 'object') { if (typeof time === 'object') {
date = time date = time
} else { } else {
if (('' + time).length === 10) time = parseInt(time) * 1000 if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
time = parseInt(time)
}
if ((typeof time === 'number') && (time.toString().length === 10)) {
time = time * 1000
}
date = new Date(time) date = new Date(time)
} }
const formatObj = { const formatObj = {