检查年份是闰年 [英] Check if year is leap year in javascript
本文介绍了检查年份是闰年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function leapYear(year){
var result;
year = parseInt(document.getElementById("isYear").value);
if (years/400){
result = true
}
else if(years/100){
result = false
}
else if(years/4){
result= true
}
else{
result= false
}
return result
}
这是我到目前为止(该条目是从这样存储在isYear) ,我基本上遵循这个这里,所以使用我已经有的,我如何检查条目是否是一个飞跃基于这些条件(注意,在实现伪代码时可能已经做错了,请修正我)
编辑:请注意,这需要使用不是日期函数的整数
This is what I have so far (the entry is on a from thus stored in "isYear"), I basically followed this here, so using what I already have, how can I check if the entry is a leap year based on these conditions(note I may have done it wrong when implementing the pseudocode, please correct me if I have) Note this needs to use an integer not a date function
推荐答案
function leapYear(year)
{
return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
}
这篇关于检查年份是闰年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文