首页 > Web开发 > 详细

js 中格式化显示时间

时间:2019-04-29 15:41:19      阅读:165      评论:0      收藏:0      [点我收藏+]

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

js 中格式化显示时间

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!