时间戳转化时间格式
时间戳转化时间格式

转化结果:
时间戳转化时间格式
const change = (t) => {
if (t < 10) {
return “0” + t;
} else {
return t;
}
}
const timestampTo2 = (timestamp, ss) => {
let date = new Date(timestamp); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
let Y = date.getFullYear();
let M = (date.getMonth() + 1 < 10 ? ‘0’ + (date.getMonth() + 1) : date.getMonth() + 1);
let D = change(date.getDate());
let h = change(date.getHours());
let m = change(date.getMinutes());
let s = change(date.getSeconds());
if(ss == ‘YMDHMS’){
return Y + ‘-’ + M + ‘-’ + D + ’ ’ + h + ‘:’ + m + ‘:’ + s;
}else if(ss == ‘YMDHM’){
return Y + ‘-’ + M + ‘-’ + D + ’ ’ + h + ‘:’ + m;
}else if(ss == ‘YM’){
return Y + ‘-’ + M ;
}else{
return Y + ‘.’ + M + ‘.’ + D;
}
}

相关文章:

  • 2021-12-08
  • 2021-10-06
  • 2021-10-08
  • 2021-12-12
  • 2021-11-28
  • 2021-11-27
  • 2021-12-26
  • 2021-11-19
猜你喜欢
  • 2021-11-28
  • 2021-07-12
  • 2021-11-28
  • 2021-12-08
  • 2021-11-28
  • 2021-12-12
  • 2021-12-05
  • 2021-11-30
相关资源
相似解决方案