js日期时间格式化

const formatTimes = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(doubleNumber).join('/') + ' ' + [hour, minute, second].map(doubleNumber).join(':')
}

const doubleNumber = num => {
  num = num.toString()
  return num[1] ? num : '0' + num
}

module.exports = {
  formatTime: formatTimes
}

 

posted @ 2018-05-23 12:28  doublealoe  阅读(295)  评论(0编辑  收藏  举报