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

这是结果

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

 

 

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

上一篇:项目积累(二)细节问题,提高用户体验


下一篇:js倒计时 天,时,分,秒