You can use the format
function from date-fns
library to format a date object in a particular format. To include timezone in the output you can use the z
or zzz
token.
Here's an example code:
index.ts201 chars7 lines
In this example, we're formatting the current date and time in the format 'yyyy-MM-dd HH:mm:ss.SSS zzz'. The HH
token is used for 24-hour format, zzz
token is used to include timezone information in the output, and SSS
token is used for milliseconds.
Note that the timezone information will be based on the timezone of the system where the code is executed. If you want to format the date in a specific timezone, you can use the utcToZonedTime
function from date-fns-tz
library to convert the date to the required timezone before formatting it.
gistlibby LogSnag