This site will have limited functionality while we undergo maintenance to improve your experience. If an article doesn't solve your issue and you want to ask a question, we have our support community waiting to help you at @FirefoxSupport on Twitter and/r/firefox on Reddit.

Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

new Date()

more options

This date '21/10/1984', does not works in new Date(). Have snome problem on because the day created is 20 but setFullYear function works fine.


function validarData(){ valor = '21/10/1984'; // <= dd/mm/yyyy format var formatoValido = new RegExp(/\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/); // format var valido = false; // default = false

if(formatoValido.test(valor)) { // check format var dia = valor.split("/")[0]; // get day var mes = valor.split("/")[1]; // get month var ano = valor.split("/")[2]; // get year var MyData = new Date(ano, mes - 1, dia); // value will be '20/10/1984'??? why day 20? <=============== // MyData.setFullYear(ano,mes - 1,dia); < uncomment this to work... setFullYear set the correct day <=============== if((MyData.getMonth() + 1 != mes)|| (MyData.getDate() != dia)|| (MyData.getFullYear() != ano)) $('#idmensagensform').text('Ops, Data incorreta.'); // warning incorrect date else valido = true; // set valid } if(valido == false){ $("#nascimento").focus(); } return valido; }




Promblem affects versions: 10.0 + Windows 7 10.0.2 + Windows 7


Theses problems not happens in FF 11 + Ubuntu 11.10

This date '21/10/1984', does not works in new Date(). Have snome problem on because the day created is 20 but setFullYear function works fine. ----------------- function validarData(){ valor = '21/10/1984'; // <= dd/mm/yyyy format var formatoValido = new RegExp(/\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/); // format var valido = false; // default = false if(formatoValido.test(valor)) { // check format var dia = valor.split("/")[0]; // get day var mes = valor.split("/")[1]; // get month var ano = valor.split("/")[2]; // get year var MyData = new Date(ano, mes - 1, dia); // value will be '20/10/1984'??? why day 20? <=============== // MyData.setFullYear(ano,mes - 1,dia); < uncomment this to work... setFullYear set the correct day <=============== if((MyData.getMonth() + 1 != mes)|| (MyData.getDate() != dia)|| (MyData.getFullYear() != ano)) $('#idmensagensform').text('Ops, Data incorreta.'); // warning incorrect date else valido = true; // set valid } if(valido == false){ $("#nascimento").focus(); } return valido; } ------------------ Promblem affects versions: 10.0 + Windows 7 10.0.2 + Windows 7 Theses problems not happens in FF 11 + Ubuntu 11.10

All Replies (1)

more options

Perhaps because my system uses mm/dd/yyyy I cannot replicate this error. Hopefully someone who uses dd/mm/yyyy can take a look. I think for purposes of testing, this is the essential part:

 
<html><head> <script type="text/javascript"> function datetest(){ valor = '21/10/1984'; // dd/mm/yyyy format var dia = valor.split("/")[0]; // get day var mes = valor.split("/")[1]; // get month var ano = valor.split("/")[2]; // get year var MyData = new Date(ano, mes - 1, dia); document.body.innerHTML += '<p>Computed new date (d/m/y) = '+MyData.toString()+'</p>'; valor = '10/21/1984'; // mm/dd/yyyy format var dia = valor.split("/")[1]; // get day var mes = valor.split("/")[0]; // get month var ano = valor.split("/")[2]; // get year var MyData = new Date(ano, mes - 1, dia); document.body.innerHTML += '<p>Computed new date (m/d/y) = '+MyData.toString()+'</p>'; } window.onload = datetest; </script> </head> <body></body> </html>