You can use Moment.js library to format date in typescript. Here is an example code snippet that formats a date in the required format:
index.ts192 chars7 lines
First, you need to import the Moment.js library using the import
statement. Then, you can create a new Date
object to get the current date and time. Next, you can use the moment
function to create a Moment object from the Date
object. Finally, you can use the format
method to format the date in the required format by passing a string containing the format tokens. In this example, MMMM
represents the full month name, D
represents the day of the month without a leading zero, YYYY
represents the four-digit year, h
represents the hours in 12-hour format, mm
represents the minutes with a leading zero, and a
represents either am
or pm
.
gistlibby LogSnag