VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-date-isvalid-api/

⇱ Node.js Date.isValid() API - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js Date.isValid() API

Last Updated : 27 Jan, 2023

The date-and-time.Date.isValid() is a minimalist collection of functions for manipulating JS date and time module which is used to validate the particular date and time with its string format.

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:

isValid(arg1[, arg2])

Parameters: This method takes the following arguments as parameters:

  • arg1: It is the date and time object.
  • arg2: It is the string format of the given date.

Return Value: This method returns true if and only if the terms are validated.

Example 1:

Run the index.js file using the following command:

node index.js

Output:

Date is not invalid

Example 2:

Run the index.js file using the following command:

node index.js

Output:

Date is valid

Reference: https://github.com/knowledgecode/date-and-time

Comment

Explore