How to use javascript to determine if it is a leap year

藏色散人
Release: 2022-01-19 16:36:46
Original
7957 people have browsed it

How to use javascript to determine whether it is a leap year: 1. Create a js sample file; 2. Pass "function isLeap(year) {if((year%4==0&&year 0!=0)|| (year@0==0)){...}" determines whether it is a leap year.

How to use javascript to determine if it is a leap year

The operating environment of this article: Windows 7 system, javascript version 1.8.5, DELL G3 computer

How to use javascript to determine whether it is a leap year?

JS determines whether it is a leap year

Conditions for determining whether it is a leap year (one of the two is met):

1. Year Can be divisible by 4, but not divisible by 100

2. The year can be divisible by 400

//判断是否为闰年
function isLeap(year) {
    if((year%4==0 && year%100!=0)||(year%400==0)){
        return 1;
    }
    return 0;
}
alert(isLeap(2019));//0
alert(isLeap(2020));//1
 
//若为闰年,返回1,反之则返回0
Copy after login

Recommended study: "js Basic Tutorial"

The above is the detailed content of How to use javascript to determine if it is a leap year. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template