perf[utils]: refine parseTime function (#1546)

* 优化 parseTime

修复传入的时间戳是字符串类型,不能转换时间的问题
例:parseTime("1548221490638")

* Update index.js
This commit is contained in:
xbigcat 2019-01-24 15:32:35 +08:00 committed by 花裤衩
parent 8ef6c7ee7d
commit 23055c9b2c

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 = {