Open In App

Moment.js moment().millisecond() Method

Last Updated : 20 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The moment().millisecond()Method is used to get the milliseconds from the time or to set the milliseconds.

Syntax:

moment().millisecond();

// or

moment().milliseconds();

Parameters: This method accepts single parameter number that is used to set milliseconds then you will require an additional parameter:

  • Number: It ranges from 0 to 1000 and used to set milliseconds in a variable.

Return Value: This function returns the current time in milliseconds.

Note: This will not work in the normal Node.js program because it requires the moment.js library to be installed. 

Moment.js can be installed using the following command:

npm install moment

Example 1: Getting current time in milliseconds.

Javascript




// Acquiring the plugin
const moment = require('moment');
 
let mili = moment().millisecond();
 
console.log("Current Milliseconds Time:", mili);


Output:

Current Milliseconds Time: 274

Example 2: Setting milliseconds time in a variable.

Javascript




// Acquiring the plugin
const moment = require('moment');
 
let mili = moment(199).millisecond();
 
console.log("Milliseconds Time:", mili);


Output:

Milliseconds Time: 199

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads