Forum Discussion
Date Format for System Date
In JavaScript, "Date" is an object with lots of information in it but sometimes, you need to give it a little bit more information to get the format you want.
var month = currentTime.getMonth() + 1 returns a number from 1 to 12. Months are actually captured as 0 through 11 in the date object which is why the code has "+ 1" at the end. To change this to the actual month name, you need to create an array of month names and then pick the one you want based on the value in your month variable. Keep in mind, arrays are numbered starting at zero, so you can actually drop the "+ 1" from the code. In your code above, replace "var month = currentTime.getMonth() + 1" with the following.
var month = currentTime.getMonth();
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var currentMonth = monthNames[month];
var day = currentTime.getDate() returns the actual date but as a number. Similar to the month names, you will need to create an array of days formatted how you want them to be displayed. Because this is the actual date, it will not align to the formatted dates in your array since the array starts at 0 and the 1st day of the month is "1". To create the alignment, you will need to subtract one from your day. In your code above replace "var day = currentTime.getDate()" with the following:
var day = currentTime.getDate();
var formatDay = ["1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "11th", "12th", "13th", "14th", "15th", "16th", "17th", "18th", "19th", "20th", "21st", "22nd", "23rd", "24th", "25th", "26th", "27th", "28th", "29th", "30th", "31st"];
var todaysDate = formatDay[day-1];
You do not need to change the year but you will need to update your date string. Replace "var dateString=month + "/" + day + "/" + year" with the following:
var dateString = todaysDate + " day of " + currentMonth + ", " + year;
This will return something like "22nd day of December, 2020".