If at all possible, without JavaScript libraries or lots of clunky code I am looking for the simplest way to format a date two weeks from now in the following format:
<
function getSuffixForDate(day) {
const lastNumberOfTheDay = day[day.length];
const suffixes = {
1: () => 'st',
21: () => 'st',
31: () => 'st',
2: () => 'nd',
22: () => 'nd',
3: () => 'rd',
23: () => 'rd',
};
return suffixes[lastNumberOfTheDay] !== undefined ? `${day}${suffixes[lastNumberOfTheDay]()}` : `${day}th`;
}
const date = new Date();
const formattedDate = `${getSuffixForDate(date.getDate())} ${monthNames[date.getMonth()]} ${date.getFullYear()}`;
A human readable version...