From aa845ab4455554e20af4706f97f3c23835fdf465 Mon Sep 17 00:00:00 2001 From: link_1999 <1402246900@qq.com> Date: Mon, 4 Apr 2022 21:48:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20'=E6=96=B0=E9=97=BB=E5=B0=8F=E7=A8=8B=E5=BA=8F/utils'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 新闻小程序/utils/util.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 新闻小程序/utils/util.js diff --git a/新闻小程序/utils/util.js b/新闻小程序/utils/util.js new file mode 100644 index 0000000..764bc2c --- /dev/null +++ b/新闻小程序/utils/util.js @@ -0,0 +1,19 @@ +const formatTime = date => { + const year = date.getFullYear() + const month = date.getMonth() + 1 + const day = date.getDate() + const hour = date.getHours() + const minute = date.getMinutes() + const second = date.getSeconds() + + return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}` +} + +const formatNumber = n => { + n = n.toString() + return n[1] ? n : `0${n}` +} + +module.exports = { + formatTime +}