Ad
Date Time

This code should show the current date in MONTH DAY(suffix) YEAR (YYYY)
Exemple: January 4th 2024

Useful in web when you want to make a current date shown automatically!

function ShowDate() {
const currentDate = new Date();

const monthsOfYear = [
  "January",
  "February",
  "March",
  "April",
  "May",
  "June",
  "July",
  "August",
  "September",
  "October",
  "November",
  "December",
];
const currentMonth = monthsOfYear[currentDate.getMonth()];
const currentDay = currentDate.getDate();
let daySuffix;
switch (currentDay) {
  case 1:
  case 21:
  case 31:
    daySuffix = "st";
    break;
  case 2:
  case 22:
    daySuffix = "nd";
    break;
  case 3:
  case 23:
    daySuffix = "rd";
    break;
  default:
    daySuffix = "th";
}
const currentYear = currentDate.getFullYear();

return `${currentMonth} ${currentDay}${daySuffix} ${currentYear}`;
}