JSFiddle - React, Tailwind, and code Playground

by charlescarver

JavaScript

var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    currentTime = new Date();
    month = monthNames[currentTime.getMonth()];
    date = new String(currentTime.getDate());
    lastDigit = date.substr(-1);
    endingLetters = "";
    th = ["0","4","5","6","7","8","9"];
    st = ["1"];
    nd = ["2"];
    rd = ["3"];


if ($.inArray(lastDigit, th) !== -1){
    endingLetters = "th";
} else if ($.inArray(lastDigit, st) !== -1){
    endingLetters = "st";
} else if ($.inArray(lastDigit, nd) !== -1){
    endingLetters = "nd";
} else if ($.inArray(lastDigit, rd) !== -1){
    endingLetters = "rd";
}

alert(month + " " + date + endingLetters);