📌  相关文章
📜  如何在javascript代码示例中将时间转换为下午

📅  最后修改于: 2022-03-11 15:03:40.453000             🧑  作者: Mango

代码示例2
const formatAMPM = (date) => {
  let hours = date.getHours();
  let minutes = date.getMinutes();    
  const ampm = hours >= 12 ? 'pm' : 'am';

  hours %= 12;
  hours = hours || 12;    
  minutes = minutes < 10 ? `0${minutes}` : minutes;

  const strTime = `${hours}:${minutes} ${ampm}`;

  return strTime;
};

console.log(formatAMPM(new Date()));