You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
46 lines
1.2 KiB
//时间格式处理工具类
|
|
|
|
//将 "2023年7月5日17时5分" 转换为 "2023-07-05 17:05:00" 格式
|
|
const customizeDateFormat = function(dateStr) {
|
|
|
|
if(dateStr == undefined || dateStr.length == 0){
|
|
return "";
|
|
}
|
|
|
|
var tempDateStr = dateStr.replace('年','-').replace('月','-').replace('日',' ').replace('时',':').replace('分',':')+'00';
|
|
// 2023-7-5 17:5:00
|
|
var tempDateArr = tempDateStr.split(' ');
|
|
var ymd = tempDateArr[0].split('-'); //年月日
|
|
var hms = tempDateArr[1].split(':'); //时分秒
|
|
|
|
var year = ymd[0]; //年
|
|
var mot = ymd[1]; //月
|
|
var day = ymd[2]; //日
|
|
//判断月份是否小于10,则前边补 0
|
|
if(mot < 10) {
|
|
mot == '0' + mot;
|
|
}
|
|
//判断日期是否小于10号,则前边补 0
|
|
if(day < 10){
|
|
day == '0' + day;
|
|
}
|
|
|
|
var hour = hms[0]; //时
|
|
var minute = hms[1]; //分
|
|
var second = hms[2]; //秒
|
|
|
|
//判断小时是否小于10,则前边补 0
|
|
if(hour < 10) {
|
|
hour = '0' + hour;
|
|
}
|
|
|
|
//判断分钟是否小于10,则前边补 0
|
|
if(minute < 10) {
|
|
minute == '0' + minute;
|
|
}
|
|
var returnDate = year + '-' + mot + '-' + day + ' ' + hour + ':' + minute + ':' + second;
|
|
return returnDate;
|
|
}//暴露出去
|
|
module.exports = {
|
|
customizeDateFormat
|
|
}; |