To format a date in the specified format, we can make use of the Moment.js library.
First, we need to install Moment.js using the following command:
19 chars2 lines
Then, we can import it in our Typescript file as follows:
index.ts34 chars2 lines
Now, we can create a Date object and pass it to moment to format it:
index.ts151 chars4 lines
In the above code, we are creating a Date object, and then passing it to moment. We are using the format function to specify the desired format for the output string.
The format string we're specifying is: MMMM D, YYYY h:mm a
Here's what each part of the format string means:
MMMM
: full month nameD
: day of the monthYYYY
: four-digit yearh
: hour (12-hour clock)mm
: minutesa
: lowercase am/pmThe resulting string is then printed to the console.
gistlibby LogSnag