美文网首页
newDate()转年月日

newDate()转年月日

作者: 小北呀_ | 来源:发表于2021-07-21 14:42 被阅读0次
const dateFormat = (dateData) => {
  const date = new Date(dateData);
  const y = date.getFullYear();
  let m = date.getMonth() + 1;
  m = m < 10 ? `0${m}` : m;
  let d = date.getDate();
  d = d < 10 ? `0${d}` : d;
  let h = date.getHours();
  h = h < 10 ? `0${h}` : h;
  let min = date.getMinutes();
  min = min < 10 ? `0${min}` : min;
  let s = date.getSeconds();
  s = s < 10 ? `0${s}` : s;
  const time = `${y}-${m}-${d} ${h}:${min}:${s}`;
  return time;
};

相关文章

网友评论

      本文标题:newDate()转年月日

      本文链接:https://www.haomeiwen.com/subject/tnsjmltx.html