Open In App

Node.js date-and-time Date.isLeapYear() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

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 module
const 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() api
const value = date.isLeapYear(now.getFullYear());
  
// display the result
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




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



Last Updated : 31 Jan, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads