js獲取當(dāng)前年月日-YYYYmmDD格式的實(shí)現(xiàn)代碼

字號:


    下面小編就為大家?guī)硪黄猨s獲取當(dāng)前年月日-YYYYmmDD格式的實(shí)現(xiàn)代碼。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。
    js獲取當(dāng)前年月日-YYYYmmDD格式的實(shí)現(xiàn)代碼
    代碼如下:
    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 dateStr = year + "-" + month + "-" + day;
    以上這篇js獲取當(dāng)前年月日-YYYYmmDD格式的實(shí)現(xiàn)代碼就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考