Node.js date-and-time Date.isLeapYeart() Method
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
// Node.js program to demonstrate the // Date.isLeapYear() method // Importing http moduleconst date = require('date-and-time') // creating object of current date and time // by using Date() const now = new Date(); // Checking the year is leap or not// by using date.isLeapYear() apiconst value = date.isLeapYear(now.getFullYear()); // display the resultif(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
// Node.js program to demonstrate the // Date.isLeapYear() method // Importing http moduleconst date = require('date-and-time') // Creating object of current date and time // by using Date() methodconst now = new Date(); now.setFullYear(2016) // Checking the year leap or not// by using date.isLeapYear() apiconst value = date.isLeapYear(now.getFullYear()); // Display the resultif(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


