在javascript中检查年份是否为闰年 [英] Check if year is leap year in javascript

查看:31
本文介绍了在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"中),我基本上遵循了这个here,所以使用我已经拥有的,我如何根据这些条件检查条目是否是闰年(注意我在实现伪代码时可能做错了,如果我有请纠正我)注意这需要使用整数而不是日期函数

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);
}

这篇关于在javascript中检查年份是否为闰年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆