format a date in to the format october 13, 2014 11:13:00.000 am gmt-07:00 in typescript

You can use the Moment.js library to format date and time values in TypeScript. Also, it is easy to use Moment-Timezone library to format date and time with timezone offset.

Here is an example of how to format a date string in the format you specified:

index.ts
import moment from "moment";
import "moment-timezone";

const inputDate = "2014-10-13T11:13:00.000Z";

const formattedDate = moment(inputDate).tz("GMT-07:00").format("MMMM DD, YYYY h:mm:ss.SSS a [(GMT]Z[)]");

console.log(formattedDate); // Output: October 13, 2014 4:13:00.000 am (GMT-07:00)
293 chars
9 lines

In the code above, we first import the Moment.js and Moment-Timezone libraries. Then, we define the input date string in ISO 8601 format. We create a moment object from this input date and use the tz method of moment object to set the timezone offset to GMT-07:00. Finally, we use the format method to create the desired output format, which includes the month, day, year, hour, minute, second, millisecond, and timezone offset.

Note that we use square brackets [] to include literal text in the output string format.

gistlibby LogSnag