Mozilla 도움말 검색

고객 지원 사기를 피하세요. 저희는 여러분께 절대로 전화를 걸거나 문자를 보내거나 개인 정보를 공유하도록 요청하지 않습니다. "악용 사례 신고"옵션을 사용하여 의심스러운 활동을 신고해 주세요.

자세히 살펴보기

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

모든 댓글 (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>