From 20881c4e4e89676b6277b45f30e5b20d121d9792 Mon Sep 17 00:00:00 2001 From: shijing Date: Fri, 12 Apr 2024 15:21:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=9F=90?= =?UTF-8?q?=E4=B8=80=E6=9C=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/tool.js | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/utils/tool.js b/src/utils/tool.js index afa440a1..0e44a085 100644 --- a/src/utils/tool.js +++ b/src/utils/tool.js @@ -190,7 +190,42 @@ tool.dateFormat1 = function (date) { newDate = year+'-'+month+'-'+day+' '+hour+':'+minute+':'+second; return newDate; } - +// 格式化某一天 +tool.dateFormat2 = function (date) { + date = new Date(date); + let newDate = ''; + let year = date.getFullYear(); + let month = date.getMonth() + 1; + let day = date.getDate(); + month = month > 9 ? month : '0' + month; + day = day > 9 ? day : '0' + day; + newDate = year+'-'+month+'-'+day; + return newDate; +} +// 格式化某一月 +tool.dateFormat2 = function (date) { + date = new Date(date); + let first = ''; + let lastDate = '',year2 = '',month2 = ''; + let year = date.getFullYear(); + let month = date.getMonth() + 1; + if (month < 12) { + year2 = year; + let mon = month + 1; + month2 = mon > 9 ? mon : '0' + mon; + } else { + year2 = year + 1; + month2 = '01'; + } + + month = month > 9 ? month : '0' + month; + first = year + '-' + month + '-01'; + lastDate = year2 + '-' + month2 + '-01'; + let arr = []; + arr.push(first) + arr.push(lastDate) + return arr; +} /* 千分符 */ tool.groupSeparator = function (num) { num = num + '';