[英]Date leap year validation
function checkDate(date)
{
//how to use this function since many people recommend this one
isLeap = new Date(date, 1, 29).getMonth() == 1;
return isLeap;
}
In html script, i wrote it as but i can't validate my Date of Order. 在html脚本中,我将其写为,但无法验证我的订购日期。 I need to use javascript and it should be able to validate it including leap year. 我需要使用javascript,它应该能够验证它,包括leap年。 The function I used above can't work. 我上面使用的功能无法正常工作。 Any helps will be appreciated. 任何帮助将不胜感激。
To check if it's leap year : 要检查是否是s年:
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
to check if the extra day is valid -- is to check how many days were in that month (and if they equal to dd): 检查额外的日期是否有效-是检查该月中有多少天(以及它们是否等于dd):
32 - new Date(2000, 1, 32).getDate()
//1 here is FEB 32 - new Date(2000, 1, 32).getDate()
// 1是FEB
do if some says : 29 feb 2000
如果有人说: 29 feb 2000
so 32 - new Date(2000, 1, 32).getDate()
//29 所以32 - new Date(2000, 1, 32).getDate()
// 29
which is fine . 很好。 cuz 29==29. 因为29 == 29。
BUT 但
do if some says : 29 feb 2001
如果有人说: 29 feb 2001
32 - new Date(2001, 1, 32).getDate()
//28 32 - new Date(2001, 1, 32).getDate()
// 28
and 28!=29 so it's not valid date. 和28!= 29,所以它不是有效日期。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.