时间戳转换为时间

const timestamp = (time, pattern) => {
  let getDate = new Date(time);

  let year = getDate.getFullYear();
  let minute = getDate.getMinutes();
  let second = getDate.getSeconds();
  let month = getDate.getMonth() + 1;
  let day = getDate.getDate();

  const addZero = (num) => {
    return num < 10 ? `0${num}` : num;
  };

  const dispose = {
    date: `${addZero(month)}月${addZero(day)}日`, // 月 日
    colon: addZero(minute) + ":" + addZero(second), // :
    point: `${year}.${addZero(month)}.${addZero(day)}`, // .
    line: `${year}-${addZero(month)}-${addZero(day)}`, // -
  };

  return dispose[pattern] || {};
};

 

posted @ 2020-09-24 15:19  印第安小铁匠  阅读(297)  评论(0编辑  收藏  举报