优化 parseTime

修复传入的时间戳是字符串类型,不能转换时间的问题
例:parseTime("1548221490638")
This commit is contained in:
xbigcat 2019-01-23 13:32:03 +08:00 committed by GitHub
parent 8cf279fbe1
commit 9f23adbc14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

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