Created
December 4, 2021 13:45
-
-
Save hebertcisco/29e350901d8f0b4a2f6e63996a8443bf to your computer and use it in GitHub Desktop.
Date Formatting Using Intl
This file contains hidden or 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 Intl from 'intl'; | |
import 'intl/locale-data/jsonp/pt-BR'; | |
export const dateFormat = (value: number | Date | undefined) => { | |
if (value) { | |
const date = new Date(value); | |
return Intl.DateTimeFormat('pt-BR', { | |
year: 'numeric', | |
month: 'numeric', | |
day: 'numeric', | |
hour: 'numeric', | |
minute: 'numeric', | |
second: 'numeric', | |
hour12: false, | |
}).format(date); | |
} | |
return ''; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment