JS获取当前时间(精确到秒)

js获取当前日期

      currentDate(){
        var d = new Date();
        var year = d.getFullYear();
        var month = d.getMonth();
        month = month + 1 > 12 ? 1 : month + 1;
        month =  month > 9 ? month : "0" +month.toString();
        var day = d.getDate();
        var hour = d.getHours();
        hour = hour > 9 ? hour : "0" + hour.toString();
        var minute = d.getMinutes();
        minute = minute > 9 ? minute : "0" + minute.toString();
        var second = d.getSeconds();
        return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
      }

 

你可能感兴趣的:(前端)