1
have that function:
function formatarData(data) {
var d = new Date(data),
mes = '' + (d.getMonth() + 1),
dia = '' + d.getDate(),
ano = d.getFullYear();
if (mes.length < 2) mes = '0' + mes;
if (dia.length < 2) dia = '0' + dia;
return [ano, mes, dia].join('');
}
and in it I can play and format the date the way I want, but when I put date 01 and month 01, it subtracts 1 year, 1 day and 1 month:
example: step to date 01/01/2018 and return 20171231.
Someone would know to tell me what’s wrong and how to concert it?
How are you passing the date to function?
– Sam
As we passed
formatarData('01/01/2018')
is returning normal:20180101
– Sam
@dvd passing input type date, the data goes as "2018-01-01"
– guilhermedjc