format a date in to the format month day, year hour:minute:second.fff am/pm zzz in javascript

You can use the toLocaleString() method in JavaScript to format a date into a specific format.

Here is an example code for formatting a date to the format month day, year hour:minute:second.fff am/pm zzz:

index.tsx
const date = new Date();
const options = {
  year: 'numeric',
  month: 'short',
  day: 'numeric',
  hour12: true,
  hour: 'numeric',
  minute: '2-digit',
  second: '2-digit',
  fractionalSecondDigits: 3,
  timeZoneName: 'short'
};

const formattedDate = date.toLocaleString('en-US', options);

console.log(formattedDate);
322 chars
17 lines

The output of the code will be something like Sep 16, 2021 11:12:30.568 AM PDT, depending on the current date and time in your timezone.

gistlibby LogSnag