A year is a leap year if the following conditions are satisfied:
- The year is a multiple of 400.
- The year is a multiple of 4 and not a multiple of 100.
Example 1: Check Leap Year Using if...else
Output
Enter a year: 2000 2000 is a leap year
In the above program, the three conditions are checked to determine if the year is a leap year or not.
The % operator returns the remainder of the division.
Example 2: Check Leap Year Using newDate()
Output
Enter a year: 2000 2000 is a leap year
In the above program, the month of February is checked if it contains 29 days.
If a month of February contains 29 days, it will be a leap year.
The new Date(2000, 1, 29) gives the date and time according to the specified arguments.
Tue Feb 29 2000 00:00:00 GMT+0545 (+0545)
The getDate() method returns the day of the month.