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 says 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 pass date in the format (dd / mm / yyyy) in new Date.
Then I need to format my date dd / mm / yyyy to mm / dd / yyyy. Could someone help me?
.