getTimestr(val){
let temp = val.toLocaleString()
if(temp.match(/[\u4e00-\u9fa5]/g)[0]=="上"){
temp = temp.replace(/[\u4e00-\u9fa5]/g,"")
return temp.slice(-8,-7)==' '? temp.slice(0,-7)+'0'+temp.slice(-7):temp
}else{
temp = temp.replace(/[\u4e00-\u9fa5]/g,"")
let templist = temp.split(' ')
let temptime = templist[1].split(':')
temptime[0] = parseInt(temptime[0])+12
temptime = temptime.join(':')
return templist[0]+' '+temptime
}
}

使用效果如下:

js最简洁的时间对象转成时间字符串的方法-LMLPHP

05-04 04:24