Node.js Date.addDays() API
The date-and-time.Date.addDays() is a minimalist collection of functions for manipulating JS date and time module which is used to add the extra Days to the existing date and time.
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:
addDays(dateObj, days)
Parameters: This method takes the following arguments as parameters:
- dateobject: It is the string object of the date.
- days: It is the number of days.
Return Value: This method returns updated date and time.
Example 1:
index.js
const date = require( 'date-and-time' )
const now = new Date();
const value = date.addDays(now, 24);
console.log( "updated date and time : " + value)
|
Run the index.js file using the following command:
node index.js
Output:
updated date and time :
Wed Mar 31 2021 20:07:07 GMT+0530 (India Standard Time)
Example 2:
index.js
const date = require( 'date-and-time' )
const now = new Date();
now.setDate(20)
const value = date.addDays(now, 24);
console.log( "updated date and time : " + value)
|
Run the index.js file using the following command:
node index.js
Output:
updated date and time :
Tue Apr 13 2021 20:09:57 GMT+0530 (India Standard Time)
Reference: https://github.com/knowledgecode/date-and-time#adddaysdateobj-days
Last Updated :
12 Mar, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...