Created
July 18, 2022 02:50
-
-
Save roshanca/08e462e197a46cec7322388985065163 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
interface Options { | |
year?: "numeric" | "2-digit" | |
month?: "long" | "short" | |
day?: "numeric" | |
} | |
export default function formatDate(date: Date | string = ""): string { | |
const options: Options = { | |
year: "numeric", | |
month: "long", | |
day: "numeric", | |
} | |
if (date instanceof Date) { | |
return date.toLocaleDateString("en-US", options) | |
} else { | |
return new Date(date).toLocaleDateString("en-US", options) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment