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

版权声明:本文为xbxxf原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/xbxxf/p/11238424.html?ivk_sa=1024320u