Last active
August 20, 2018 15:30
-
-
Save lennonfuston/5d3539335e55c9aa3c8604483e775853 to your computer and use it in GitHub Desktop.
Funcão de formatação de data para o formato pt-BR em JavaScript
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
/** | |
* Formatar o dia de hoje: formatDateBr(new Date()); | |
* Formatar um dia em especifico: formatDateBr(new Date('2018-08-20')); | |
* Formatar um timestamp especifico: formatDateBr(new Date(1534778906831)); | |
*/ | |
function formatDateBr(data) { | |
const dia = data.getDate() < 10 ? '0'+data.getDate() : data.getDate(); | |
const mes = (data.getMonth()+1) < 10 ? '0'+(data.getMonth()+1) : (data.getMonth()+1); | |
const ano = data.getFullYear(); | |
return dia+'/'+mes+'/'+ano; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment