Open In App

Node.js date-and-time Date.addMilliseconds() Method

Improve
Improve
Like Article
Like
Save
Share
Report

The date-and-time Date.addMilliseconds() method is used to add the extra Milliseconds to the existing date and time.

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:

const addMilliseconds(dateObj, seconds)

Parameters: This method takes the following arguments as a parameter:

  • dateobject: It is the string object of the date.
  • seconds: It is the number of milliseconds to be added.

Return Value: This method returns updated date and time.

Example 1:

index.js




// Node.js program to demonstrate the  
// Date.addMilliseconds() method
  
// Importing date-and-time module
const date = require('date-and-time')
  
// Creating object of current date
// and time using Date() method
const now  =  new Date();
  
// Adding Milliseconds to the existing date and time
// by using date.addMilliseconds() method
const value = date.addMilliseconds(now,24);
  
// Display the result
console.log("updated date and time :- " + value)


Run the index.js file using the following command:

node index.js

Output:

updated date and time :- Fri Mar 19 2021 18:15:26 GMT+0530 (India Standard Time)

Example 2:

index.js




// Node.js program to demonstrate the  
// Date.addMilliseconds() method
  
// Importing date-and-time module
const date = require('date-and-time')
  
// Creating object of current date 
// and time using Date() method
const now  =  new Date();
  
now.setDate(20)
  
// Adding Milliseconds to the existing
// date and time by using
// date.addMilliseconds() method
const value = date.addMilliseconds(now,30);
  
// Display the result
console.log("updated date and time :- " + value)


Run the index.js file using the following command:

node index.js

Output:

updated date and time :- Sat Mar 20 2021 18:16:05 GMT+0530 (India Standard Time)

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



Last Updated : 25 Mar, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads