Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Node.js util.types.isDate() Method

  • Last Updated : 08 Oct, 2021

The util.types.isDate() method is an inbuilt application programming interface of the util module which is used to check type for Date in the node.js.

Syntax:

util.types.isDate( value )

Parameters: This method accepts single parameter as mentioned above and described below.

  • value: It is a required parameter of any datatype.

Return Value: This returns a boolean value, TRUE if the value is a Date object, FALSE otherwise.

Below examples illustrate the use of util.types.isDate() method in Node.js:

Example 1:




// Node.js program to demonstrate the   
// util.types.isDate() Method
  
// Allocating util module
const util = require('util');
  
// Value to be passed as parameter
// of util.types.isDate() method
var v1 = new Date();
var v2 = 3 / 6 / 96;
  
// Printing the returned value from
// util.types.isDate() method
console.log(util.types.isDate(v1));
console.log(util.types.isDate(v2));

Output:

true
false

Example 2:




// Node.js program to demonstrate the   
// util.types.isDate() Method
  
// Allocating util module
const util = require('util');
  
// Value to be passed as parameter
// of util.types.isDate() method
var v1 = new Date();
var v2 = 3 / 6 / 96;
  
// Calling util.types.isDate() method
if (util.types.isDate(v1))
    console.log("The passed value is a Date.");
else
    console.log("The passed value is not a Date");
  
if (util.types.isDate(v2))
    console.log("The passed value is a Date.");
else
    console.log("The passed value is not a Date");

Output:

The passed value is a Date.
The passed value is not a Date

Note: The above program will compile and run by using the node filename.js command.

Reference: https://nodejs.org/api/util.html#util_util_types_isdate_value


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!