其他分享
首页 > 其他分享> > js获取当前时间:yyyy-MM-dd HH:MM:SS

js获取当前时间:yyyy-MM-dd HH:MM:SS

作者:互联网

var nowDate = new Date();var year = nowDate.getFullYear();

 var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1): nowDate.getMonth() + 1;

 var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
  
  var hours = nowDate.getHours()<10?"0" + nowDate.getHours():nowDate.getHours();
var minutes = nowDate.getMinutes()<10?"0" + nowDate.getMinutes():nowDate.getMinutes();
var seconds = nowDate.getSeconds()<10?"0" + nowDate.getSeconds():nowDate.getSeconds();

 var dateStr = year + "-" + month + "-" + day+ " " + hours+ ":" + minutes+ ":" + seconds;
 console.log(dateStr);

这是结果

 

 

我要转html5和js,哎,其实还挺喜欢写后端的,但是希望自己转变一下,加油吧

标签:10,MM,dd,js,SS,nowDate,var,getMonth,getDate
来源: https://www.cnblogs.com/xbxxf/p/11238424.html