2
I’m getting this date in a variable:
var data = "23/03/2012 00:00:00"
I need to put this date in an input type date. When I try, the message appears saying that I need to pass through the format (yyyy-mm-dd)
I found this function that formats date:
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('-');
}
However, when I try to execute the function with the date I’m receiving, it returns (Nan-Nan-Nan).
I searched here on the internet, and saw that you can not date in the format (dd/mm/yyyy) in the new date.
Ai need to format my date dd/mm/yyyy to mm/dd/yyyy. Could someone help me?
.
Possible duplicate of How to format date in javascript?
– William Aparecido Brandino
The other question or answer didn’t work?
– Valdeir Psr
No, because there is using new date before formatting date, different date formats
– guilhermedjc