js 中格式化显示时间

function getMyDateTime(str){
var oDate = new Date(str),
oYear = oDate.getFullYear(),
oMonth = oDate.getMonth()+1< 10 ? "0" + (oDate.getMonth()+1) : (oDate.getMonth()+1);
oDay = oDate.getDate()< 10 ? "0" + oDate.getDate() : oDate.getDate();
oHour = oDate.getHours() < 10 ? "0" + oDate.getHours() : oDate.getHours();
oMinute = oDate.getMinutes() < 10 ? "0" + oDate.getMinutes() : oDate.getMinutes();
oSecond = oDate.getSeconds() < 10 ? "0" + oDate.getSeconds() : oDate.getSeconds();

oTime = oYear +'-'+ oMonth +'-'+ oDay +" "+ oHour + ":" + oMinute + ":" +oSecond;//最后拼接时间
return oTime;
};

原文地址:https://www.cnblogs.com/littleapple/p/10790632.html