JS格式化输出当前时间戳:getDateTimeString()

发布时间 2024-01-05 11:07:16作者: 袜子破了
function getDateTimeString() {
  const now = new Date()
  const year = now.getFullYear();
  const month = now.getMonth() + 1;
  const day = now.getDay();
  const hours = now.getHours();
  const minutes = now.getMinutes();
  const seconds = now.getSeconds();
  return [year, month, day, hours, minutes, seconds].map((num) => {
    if (num < 10) {
      return '0' + num;
    }
    return num;
  }).join('')
}