The util.types.isDate() method is an inbuilt application programming interface of the util module which is used to check the type for Date in the node.js.
Syntax:
util.types.isDate( value )
Parameters: This method accepts a 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.
Example 1: The below example illustrates the use of util.types.isDate() method in Node.js:
// 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
let v1 = new Date();
let 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: In this example, we will illustrate the use of util.types.isDate() method in Node.js
// 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
let v1 = new Date();
let 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