From 646162593ebcbbfe875415d51583b3f2fc044beb Mon Sep 17 00:00:00 2001 From: isummer Date: Mon, 17 Oct 2022 10:03:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=93=E5=8C=85=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fir_client/src/utils/format.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 fir_client/src/utils/format.js diff --git a/fir_client/src/utils/format.js b/fir_client/src/utils/format.js new file mode 100644 index 0000000..e4e5037 --- /dev/null +++ b/fir_client/src/utils/format.js @@ -0,0 +1,22 @@ +module.exports =function dateFormat(format, date=null) { + if(!date){ + date = new Date() + } + const args = { + "M+": date.getMonth() + 1, + "d+": date.getDate(), + "h+": date.getHours(), + "m+": date.getMinutes(), + "s+": date.getSeconds(), + "q+": Math.floor((date.getMonth() + 3) / 3), + "S": date.getMilliseconds() + }; + if (/(y+)/.test(format)) + format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length)); + for (let i in args) { + let n = args[i]; + if (new RegExp("(" + i + ")").test(format)) + format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? n : ("00" + n).substr(("" + n).length)); + } + return format; +}