One way to format a date in the desired format is by using the Moment.js library. Here's an example:
index.tsx230 chars9 lines
In the above code, the format
method of Moment.js is used to format the date. The format string MMMM Do, YYYY h:mm:ss A
specifies the desired format, where:
MMMM
represents the full name of the monthDo
represents the day of the month with the suffix (e.g. 1st, 2nd, 3rd)YYYY
represents the full 4-digit yearh
represents the hour in 12-hour formatmm
represents the minutesss
represents the secondsA
represents the AM/PM markerRunning the above code would output a string like June 14th, 2021 10:30:15 AM
, depending on the current date and time.
gistlibby LogSnag