Skip to content

Instantly share code, notes, and snippets.

@lennonfuston
Last active August 20, 2018 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lennonfuston/5d3539335e55c9aa3c8604483e775853 to your computer and use it in GitHub Desktop.
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
/**
* 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