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;
};


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM