Created
February 28, 2024 18:56
-
-
Save kellenmace/eceef05aaeacae525afe251c3c3b4842 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { formatDistance, parseISO } from 'date-fns'; | |
// Example string date | |
const dateString: string = "2023-05-23"; | |
// Parse the string date into a JavaScript Date object | |
const date: Date = parseISO(dateString); | |
// Get the current date | |
const currentDate: Date = new Date(); | |
// Calculate the relative date string | |
const relativeDateString: string = formatDistance(date, currentDate, { addSuffix: true }); | |
console.log(`Relative date: ${relativeDateString}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment