To use the formatDistance
function from the date-fns library in TypeScript, first you need to install the library:
21 chars2 lines
Then, import the function in your TypeScript file:
index.ts43 chars2 lines
Now you can use the formatDistance
function to format the distance between two dates:
index.ts168 chars8 lines
In this example, the formatDistance
function is used to format the distance between January 1st and January 15th, 2020. The addSuffix
option is set to true
, which adds the word "in" before the formatted distance.
gistlibby LogSnag