Last active
August 22, 2018 19:02
-
-
Save lennonfuston/e358352a5139501e4d6f6473bb872a00 to your computer and use it in GitHub Desktop.
Função para converter Datetime em Date
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
/** | |
* 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