Home >Web Front-end >Front-end Q&A >How to use javascript to determine if it is a leap year
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.
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
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!