js将2021-08-21T10:00:18.000+00:00转换成年月日时分秒

export const transformTimestamp = (timestamp) => {
  //let a = new Date(timestamp).getTime();
  //const date = new Date(a);
  const date=new Date(timestamp)
  const Y = date.getFullYear() + '-';
  const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  const D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + '  ';
  const h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  const m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes())+ ':';
  const s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()); // 秒
  const dateString = Y + M + D + h + m+s;
  return dateString;
}

你可能感兴趣的:(js)