Examples of Date object and functions

First: let dt = new Date(); // current date/time

dt.toLocaleString():
dt.getMonth(): [0-11, with January==0]
dt.getDate(): [1-31]
dt.getDay(): [0-6, with Sunday==0]
dt.getFullYear():
dt.getHours(): [0-23]
dt.getMinutes(): [0-59]
dt.getSeconds(): [0-59]

Second: dt = new Date("2018-03-09T09:18:00"); // specified state/time

dt.toLocaleString():
dt.getMonth(): [0-11, with January==0]
dt.getDate(): [1-31]
dt.getDay(): [0-6, with Sunday==0]
dt.getFullYear():
dt.getHours(): [0-23]
dt.getMinutes(): [0-59]
dt.getSeconds(): [0-59]

Third: Set fields individually (to January 1, 2003, 12:34:56)

dt.setMonth(0);
dt.setDate(1);
dt.setFullYear(2003);
dt.setHours(12);
dt.setMinutes(34);
dt.setSeconds(56);
dt.toLocaleString():
dt.getMonth(): [0-11, with January==0]
dt.getDate(): [1-31]
dt.getDay(): [0-6, with Sunday==0]
dt.getFullYear():
dt.getHours(): [0-23]
dt.getMinutes(): [0-59]
dt.getSeconds(): [0-59]

Fourth: Using the dataformat.js library

Make sure you include the dateformat.js library using a script element. Create a Date object. Then you can get back a formatted string based on that date using the Date's new .format(formatString) function. Anything in the format string will stay as it is, except for specific two character sequences starting with a % sign. Here are the recognized sequences:

Fifth: dt = new Date(); // current date/time

dt.format("Short day: %a, Long day: %A"):
dt.format("Short month: %b, Long month: %B"):
dt.format("Day of month (zero pad): %d, Day of month (space pad): %e"):
dt.format("Year (first two digits): %C, Year (last two digits): %y"):
dt.format("AM/PM: %p, am/pm: %P"):
dt.format("24 hour: %k, 12 hour: %l"):
dt.format("Zero padded 24 hour: %H, 12 hour: %I"):
dt.format("Date format: %D"):
dt.format("Date format: %F"):
dt.format("Date: %A, %B %e%$, %Y   Time: %l:%M %P"):