时间戳转年月日格式

     function formatDate(timestamp) {
        var date = new Date(timestamp);
        var year = date.getFullYear();
        var month = addZero(date.getMonth() + 1);
        var day = addZero(date.getDate());
        var hours = addZero(date.getHours());
        var minutes = addZero(date.getMinutes());
        var seconds = addZero(date.getSeconds());
        // return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
        return year + '-' + month + '-' + day;
      }

      function addZero(num) {
        return num < 10 ? '0' + num : num;
      }
 // 调用formatDate
formatDate(time)

你可能感兴趣的:(javascript)