To use the formatRFC3339
function from the date-fns
library in TypeScript, you first need to import it from the library:
index.ts42 chars2 lines
Then, you can call the function with a date object to format it into an RFC 3339 string:
index.ts136 chars4 lines
The formatRFC3339
function can also take an optional additionalDigits
parameter, which specifies the precision of the seconds in the output string. The default value is 3, which includes milliseconds, but you can set it to 0 to exclude milliseconds:
index.ts157 chars4 lines
Note that the formatRFC3339
function returns a string in the UTC timezone with a "Z" at the end to indicate the timezone offset. If you need to display the date in a different timezone, you can use the utcToZonedTime
function from the date-fns-tz
library to convert the date object to a timezone-specific date object before formatting it with formatRFC3339
.
gistlibby LogSnag