时间戳转化为yy-mm-dd等

function getTimeStr(timeNum){
  var dateTime = new Date(parseInt(timeNum))
  var year = dateTime.getFullYear();
  var month = dateTime.getMonth() + 1;
  if(month > 0 && month <10){
    month = "0" + month;
  }
  var day = dateTime.getDate();
  if(day > 0 && day < 10){
    day = "0"+day;
  }
  var hour = dateTime.getHours();
  if(hour > 0 && hour < 10){
    hour = "0"+hour;
  }
  var minute = dateTime.getMinutes();
  if(minute > 0 && minute < 10){
    minute = "0"+minute;
  }
  var second = dateTime.getSeconds();
  if(second > 0 && second < 10){
    second = "0"+second;
  }
  var timeSpanStr = year + '-' + month + '-' + day  + '-' + hour + '-' + minute + '-' + second ;
  return timeSpanStr;      
}
// 获取当前毫秒的时间戳
var timestamp=new Date().getTime();
console.log(getTimeStr(timestamp));

上一篇:21天养成好习惯(第15天)


下一篇:【题解】CF1609 Deltix Round, Autumn 2021 (Div. 1 + Div. 2)