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 + '';