From 0a380afbb08987fb276dbe49db068b6331b8da4c Mon Sep 17 00:00:00 2001 From: Dong Xia Date: Wed, 1 Feb 2023 05:18:58 +0000 Subject: [PATCH 1/3] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20src?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/.keep diff --git a/src/.keep b/src/.keep new file mode 100644 index 0000000..e69de29 -- Gitee From 3b0efc1e56fdb08289a215bf0c086bfd051c6d96 Mon Sep 17 00:00:00 2001 From: Dong Xia Date: Wed, 1 Feb 2023 05:19:29 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20utils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/utils/.keep diff --git a/src/utils/.keep b/src/utils/.keep new file mode 100644 index 0000000..e69de29 -- Gitee From 816d04fdd3b43ce5ab2a0da6320eb488b5ddb426 Mon Sep 17 00:00:00 2001 From: Dong Xia Date: Wed, 1 Feb 2023 05:21:20 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=A0=BC=E5=BC=8F=E5=8C=96=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=B7=A5=E5=85=B7=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dong Xia --- src/utils/time.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/utils/time.js diff --git a/src/utils/time.js b/src/utils/time.js new file mode 100644 index 0000000..715f1bf --- /dev/null +++ b/src/utils/time.js @@ -0,0 +1,37 @@ +// 转换时间 +export function parseTime(time, cFormat) { + if (arguments.length === 0) { + return null + } + // 处理 time 参数 + if (isNaN(Number(time)) === false) { + time = Number(time) + } + const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}' + let date + if (typeof time === 'object') { + date = time + } else { + if (('' + time).length === 10) time = parseInt(time) * 1000 + date = new Date(time) + } + const formatObj = { + y: date.getFullYear(), + m: date.getMonth() + 1, + d: date.getDate(), + h: date.getHours(), + i: date.getMinutes(), + s: date.getSeconds(), + a: date.getDay() + } + const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => { + let value = formatObj[key] + // Note: getDay() returns 0 on Sunday + if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] } + if (result.length > 0 && value < 10) { + value = '0' + value + } + return value || 0 + }) + return time_str +} -- Gitee