自用时间格式化

·  阅读 224

请求接口得到value=2020-03-04T05:29:04.000+0000

export function formatTime(value) {
  const sd = new Date(value);
  const year = sd.getFullYear();
  const month = formatNum(sd.getMonth() + 1);
  const date = formatNum(sd.getDate());
  const hours = formatNum(sd.getHours());
  const minutes = formatNum(sd.getMinutes());
  const seconds = formatNum(sd.getSeconds());
  const filterDate = `${year}-${month}-${date}  ${hours}:${minutes}:${seconds}`;
  return filterDate;
}
function formatNum(num) {
  if (num <= 9) {
    return "0" + num;
  } else {
    return num;
  }
}
复制代码
分类:
前端
标签:
分类:
前端
标签:
收藏成功!
已添加到「」, 点击更改