From 9f23adbc14e12001c5920e5ec4a71255feb1fe54 Mon Sep 17 00:00:00 2001 From: xbigcat Date: Wed, 23 Jan 2019 13:32:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20parseTime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复传入的时间戳是字符串类型,不能转换时间的问题 例:parseTime("1548221490638") --- src/utils/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/utils/index.js b/src/utils/index.js index 0445827b..ab240b1e 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -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 = {