优化时间工具类

This commit is contained in:
神话
2022-05-04 11:05:11 +08:00
parent 0d60fd5306
commit d436976228

View File

@@ -480,51 +480,57 @@ export function getMpListShort(thisRows, checker, replacer) {
return mPropertyListShort return mPropertyListShort
} }
/**
* js获取当前年份 格式“yyyy”
*/
export function getNowFormatYear() {
let date = new Date();
return date.getFullYear();
}
/** /**
* js获取当前月份 格式“yyyy-MM” * js获取当前月份 格式“yyyy-MM”
*/ */
export function getNowFormatMonth() { export function getNowFormatMonth() {
var date = new Date(); let date = new Date();
var seperator1 = "-"; let seperator1 = "-";
var month = date.getMonth() + 1; let month = date.getMonth() + 1;
if (month >= 1 && month <= 9) { if (month >= 1 && month <= 9) {
month = "0" + month; month = "0" + month;
} }
var currentdate = date.getFullYear() + seperator1 + month; return date.getFullYear() + seperator1 + month;
return currentdate;
} }
/** /**
* js获取当前日期 格式“yyyy-MM-dd” * js获取当前日期 格式“yyyy-MM-dd”
*/ */
export function getFormatDate() { export function getFormatDate() {
var date = new Date(); let date = new Date();
var seperator1 = "-"; let seperator1 = "-";
var year = date.getFullYear(); let year = date.getFullYear();
var month = date.getMonth() + 1; let month = date.getMonth() + 1;
var strDate = date.getDate(); let strDate = date.getDate();
if (month >= 1 && month <= 9) { if (month >= 1 && month <= 9) {
month = "0" + month; month = "0" + month;
} }
if (strDate >= 0 && strDate <= 9) { if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate; strDate = "0" + strDate;
} }
var currentdate = year + seperator1 + month + seperator1 + strDate; return year + seperator1 + month + seperator1 + strDate;
return currentdate;
} }
/** /**
* js获取当前时间 格式“yyyy-MM-dd HH:MM:SS” * js获取当前时间 格式“yyyy-MM-dd HH:MM:SS”
*/ */
export function getNowFormatDateTime() { export function getNowFormatDateTime() {
var date = new Date(); let date = new Date();
var seperator1 = "-"; let seperator1 = "-";
var seperator2 = ":"; let seperator2 = ":";
var month = date.getMonth() + 1; let month = date.getMonth() + 1;
var strDate = date.getDate(); let strDate = date.getDate();
var strHours = date.getHours(); let strHours = date.getHours();
var strMinutes = date.getMinutes(); let strMinutes = date.getMinutes();
var strSeconds = date.getSeconds(); let strSeconds = date.getSeconds();
if (month >= 1 && month <= 9) { if (month >= 1 && month <= 9) {
month = "0" + month; month = "0" + month;
} }
@@ -540,22 +546,21 @@ export function getNowFormatDateTime() {
if (strSeconds >= 0 && strSeconds <= 9) { if (strSeconds >= 0 && strSeconds <= 9) {
strSeconds = "0" + strSeconds; strSeconds = "0" + strSeconds;
} }
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate return date.getFullYear() + seperator1 + month + seperator1 + strDate
+ " " + strHours + seperator2 + strMinutes + " " + strHours + seperator2 + strMinutes
+ seperator2 + strSeconds; + seperator2 + strSeconds;
return currentdate;
} }
/** /**
* js获取当前时间 格式“MMddHHMMSS” * js获取当前时间 格式“MMddHHMMSS”
*/ */
export function getNowFormatStr() { export function getNowFormatStr() {
var date = new Date(); let date = new Date();
var month = date.getMonth() + 1; let month = date.getMonth() + 1;
var strDate = date.getDate(); let strDate = date.getDate();
var strHours = date.getHours(); let strHours = date.getHours();
var strMinutes = date.getMinutes(); let strMinutes = date.getMinutes();
var strSeconds = date.getSeconds(); let strSeconds = date.getSeconds();
if (month >= 1 && month <= 9) { if (month >= 1 && month <= 9) {
month = "0" + month; month = "0" + month;
} }
@@ -571,7 +576,7 @@ export function getNowFormatStr() {
if (strSeconds >= 0 && strSeconds <= 9) { if (strSeconds >= 0 && strSeconds <= 9) {
strSeconds = "0" + strSeconds; strSeconds = "0" + strSeconds;
} }
var currentdate = month + strDate + strHours + strMinutes + strSeconds; let currentdate = month + strDate + strHours + strMinutes + strSeconds;
return currentdate; return currentdate;
} }
@@ -595,7 +600,7 @@ export function removeByVal(arrylist, val) {
* @returns {Array} * @returns {Array}
*/ */
export function changeListFmtMinus(arr) { export function changeListFmtMinus(arr) {
var newArr = new Array(); let newArr = new Array();
for(var i=0; i<arr.length; i++) { for(var i=0; i<arr.length; i++) {
if(arr[i] < 0){ if(arr[i] < 0){
newArr.push((arr[i]-0).toString()); newArr.push((arr[i]-0).toString());