1、new Date()格式转 字符串格式
Fri Jan 01 2010 00:00:00 GMT+0800 (中国标准时间)
转成:
2010-01-01 00:00:00
js代码函数:
value是Mon May 06 2019 04:05:00 GMT+0800 (中国标准时间)
getNowFormatDate(value){ var CurrentDate = ""; var Year = value.getFullYear(); var Month = value.getMonth()+1; var Day = value.getDate(); var Hours = value.getHours(); var Minutes = value.getMinutes(); var MonthVal = (Month >= 10)?Month:'0'+Month; var DayVal = (Day >= 10)?Day:'0'+Day; var HoursVal = (Hours >= 10)?Hours:'0'+Hours; var MinutesVal = (Minutes >= 10)?Minutes:'0'+Minutes; CurrentDate = Year +'-'+MonthVal+'-'+DayVal+' '+HoursVal+':'+MinutesVal+':00'; return CurrentDate; },
2、 比较两个时间大小
/* 比较两个字符串,比较的是转换之后的: self.dateCompare("2019-03-01 05:23","2019-03-01 02:34") */ dateCompare(startString, endString){ var startTimeString = new Date(startString); var endTimeString = new Date(endString); var startTime = startTimeString.getTime(); var endTime = endTimeString.getTime(); if(endTime > startTime){ // return '开始 < 结束'; return 1; }else if(startTime == endTime){ //return '相等'; return 0; }else{ //return '开始 > 结束'; return -1 } },