📜  后缀日期 javascript 代码示例

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

代码示例1
const nth = function(d) {
  if (d > 3 && d < 21) return 'th';
  switch (d % 10) {
    case 1:  return "st";
    case 2:  return "nd";
    case 3:  return "rd";
    default: return "th";
  }
}
const fortnightAway = new Date(+new Date + 12096e5);
const date = fortnightAway.getDate();
const month = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][fortnightAway.getMonth()];

document.getElementById("date").innerHTML = `${date}${nth(date)} ${month} ${fortnightAway.getFullYear()}`;