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.ts293 chars9 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