Created
January 27, 2022 21:41
-
-
Save nathanlogan/828abceb440b9533c2a8e07e5e95bd7f to your computer and use it in GitHub Desktop.
Convert date string to user's locale
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
export const formatDateAsDefaultLocale = (incomingDate: string | Date, options?: Intl.DateTimeFormatOptions): string => { | |
const defaultOptions = { day: 'numeric', month: 'short', year: 'numeric' } | |
const date = new Date(incomingDate) | |
return date.toString() !== "Invalid Date" ? date.toLocaleString('default', options || defaultOptions) : ''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment