Node.js Date.parse() API
Last Updated :
12 Mar, 2021
The date-and-time.Date.parse() is a minimalist collection of functions for manipulating JS date and time module which is used to parse the date according to a certain pattern.
Required Module: Install the module by npm or used it locally.
npm install date-and-time --save
<script src="/path/to/date-and-time.min.js"></script>
Syntax:
parse(dateString, arg)
Parameters: This method takes the following arguments as parameters:
- dateString: It is the string object of the date
- arg: It is the required date format.
Return Value: This method returns parsed date and time.
Example 1:
index.js
const date = require( 'date-and-time' )
const now = new Date( '07-03-2021' );
const value = date.parse(now.toLocaleDateString(), 'D/M/YYYY' );
console.log( "parsed date and time : " + value)
|
Run the index.js file using the following command:
node index.js
Output:
parsed date and time :
Thu Jan 01 1970 00:00:00 GMT+0530 (India Standard Time)
Example 2:
index.js
const date = require( 'date-and-time' )
const value = date.parse( '23:14:05 GMT+0900' , 'HH:mm:ss [GMT]Z' );
console.log( "Parsed date and time : " + value)
|
Run the index.js file using the following command:
node index.js
Output:
Parsed date and time :
Thu Jan 01 1970 19:44:05 GMT+0530 (India Standard Time)
Reference: https://github.com/knowledgecode/date-and-time
Share your thoughts in the comments
Please Login to comment...