showing results for - "postfix date javascript"
Tiago
05 Nov 2018
1const nth = function(d) {
2  if (d > 3 && d < 21) return 'th';
3  switch (d % 10) {
4    case 1:  return "st";
5    case 2:  return "nd";
6    case 3:  return "rd";
7    default: return "th";
8  }
9}
10const fortnightAway = new Date(+new Date + 12096e5);
11const date = fortnightAway.getDate();
12const month = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][fortnightAway.getMonth()];
13
14document.getElementById("date").innerHTML = `${date}<sup>${nth(date)}</sup> ${month} ${fortnightAway.getFullYear()}`;