Skip to content

Instantly share code, notes, and snippets.

@lennonfuston
Last active August 22, 2018 19:02
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/e358352a5139501e4d6f6473bb872a00 to your computer and use it in GitHub Desktop.
Save lennonfuston/e358352a5139501e4d6f6473bb872a00 to your computer and use it in GitHub Desktop.
Função para converter Datetime em Date
/**
* Converter o dia de hoje: formatDate(new Date());
* Converter um dia em especifico: formatDate(new Date('2018-08-20'));
* Converter um timestamp especifico: formatDate(new Date(1534778906831));
*/
function formatDate(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 ano+'-'+mes+'-'+dia;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment