format a date in to the format october 13, 2014 11:13:00 am in javascript

You can use Moment.js library to format dates easily. First, create a Moment object with the date string and then format it using the format method as follows:

index.tsx
const dateString = '2014-10-13 11:13:00';
const formattedDate = moment(dateString).format('MMMM DD, YYYY h:mm:ss a');
console.log(formattedDate); // October 13, 2014 11:13:00 am
178 chars
4 lines

In the format method, MMMM represents the full month name, DD represents the day of the month with leading zeros, YYYY represents the four-digit year, h represents the hour in 12-hour format, mm represents the minutes with leading zeros, ss represents the seconds with leading zeros, and a represents either am or pm.

gistlibby LogSnag