From 3ba75a454432f1f22f688378f0e5c4e4fd1bc939 Mon Sep 17 00:00:00 2001 From: wuhanqing Date: Thu, 15 Oct 2020 09:28:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B3=A8=E5=86=8C=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=98=BE=E7=A4=BA=E6=A0=BC=E5=BC=8F=E4=B8=AA=E4=BD=8D?= =?UTF-8?q?=E6=95=B0=E8=A1=A5=E9=9B=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/index.js b/src/utils/index.js index b7fa49ca..9a2ea4f6 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -156,6 +156,10 @@ export function basename(path){ return pathList.join("/") === "" ? "/" : pathList.join("/") } +function addZero(m) { + return m < 10 ? '0' + m : m; +} + export function transformTime(timestamp = +new Date()) { if (timestamp) { const time = new Date(timestamp); @@ -165,7 +169,7 @@ export function transformTime(timestamp = +new Date()) { const h = time.getHours(); // getHours方法返回 Date 对象的小时 (0 ~ 23) const m = time.getMinutes(); // getMinutes方法返回 Date 对象的分钟 (0 ~ 59) const s = time.getSeconds(); // getSeconds方法返回 Date 对象的秒数 (0 ~ 59) - return y + '-' + M + '-' + d + ' ' + h + ':' + m + ':' + s; + return y + '-' + addZero(M) + '-' + addZero(d) + ' ' + addZero(h) + ':' + addZero(m) + ':' + addZero(s); } else { return ''; }