The date-and-time.Date.isLeapYear() is a minimalist collection of functions for manipulating JS date and time module which is used to check if the given year is a leap year or not.
Required Module: Install the module by npm or used it locally.
By using npm:
npm install date-and-time --save
By using CDN link:
<script src="/path/to/date-and-time.min.js"></script>
Syntax:
const isLeapYear(y)
Parameters: This Method takes a string of year.
Return Value: This method returns the Boolean value true if and only if the string of year is leap.
Example 1:
index.js
const date = require( 'date-and-time' )
const now = new Date();
const value = date.isLeapYear(now.getFullYear());
if (value)
console.log( "This is a leap year" )
else
console.log( "This is not a leap year" )
|
Run index.js file using below command:
node index.js
Output:
This is not a leap year
Example 2:
index.js
const date = require( 'date-and-time' )
const now = new Date();
now.setFullYear(2016)
const value = date.isLeapYear(now.getFullYear());
if (value)
console.log( "This is a leap year" )
else
console.log( "This is not a leap year" )
|
Run index.js file using below command:
node index.js
Output:
This is a leap year
Reference: https://github.com/knowledgecode/date-and-time#isleapyeary