JS 获取当前时间的字符串

js获取当前时间的字符串.了解更多,请前往个人博客:风尘博客 http://www.dustyblog.cn/213.html

 

function getNowFormatDate() {

  1.     var date = new Date();
  2.     var seperator1 = "-";
  3.     var seperator2 = ":";
  4.     var month = date.getMonth() + 1;
  5.     var strDate = date.getDate();
  6.     if (month >= 1 && month <= 9) {
  7.         month = "0" + month;
  8.     }
  9.     if (strDate >= 0 && strDate <= 9) {
  10.         strDate = "0" + strDate;
  11.     }
  12.     var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
  13.             + " " + date.getHours() + seperator2 + date.getMinutes()
  14.             + seperator2 + date.getSeconds();
  15.     return currentdate;
  16. }

猜你喜欢

转载自blog.csdn.net/qq_41690817/article/details/80216137