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,哎,其实还挺喜欢写后端的,但是希望自己转变一下,加油吧

posted @ 2019-07-24 15:40  西贝小小凤  阅读(824)  评论(0编辑  收藏  举报