当前位置: 代码迷 >> 综合 >> JS 时间戳 转为正常时间格式
  详细解决方案

JS 时间戳 转为正常时间格式

热度:38   发布时间:2023-10-21 12:52:13.0
//JS时间戳转为YYYY-MM-DD HH:mm:ss
function exChangeTime(timeStamp){
var str = "";
str += timeStamp.getFullYear() + '-';
timeStamp.getMonth() < 10 ? str += '0' + (timeStamp.getMonth() + 1) + '-' : str += (timeStamp.getMonth() + 1) + '-';
timeStamp.getDate() < 10 ? str += '0' + timeStamp.getDate() + ' ' : str += timeStamp.getDate() + ' ';
timeStamp.getHours() < 10 ? str += '0' + timeStamp.getHours() + ':' : str += timeStamp.getHours() + ':';
timeStamp.getMinutes() < 10 ? str += '0' + timeStamp.getMinutes() + ':' : str += timeStamp.getMinutes() + ':';
timeStamp.getSeconds() < 10 ? str += '0' + timeStamp.getSeconds(): str += timeStamp.getSeconds();
return str;
}
  相关解决方案