Open In App

Moment.js moment.duration(Number) Method

Last Updated : 18 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The moment.duration() function can be used to create durations. Duration objects are defined as intervals of time.

Syntax:

moment.duration(Number)

Parameters: It takes a number as a parameter which is used to signify the length of time in milliseconds.

Returns: A Duration object

Example 1:

Javascript




import moment from 'moment';
  
let minute = 60 * 1000;
let duration = moment.duration(minute);
console.log(duration.humanize());


Output:

 

Example 2:

Javascript




import moment from 'moment';
  
let duration = moment.duration(250);
console.log(duration.asMilliseconds());


Output:

 

Reference: https://momentjs.com/docs/#/durations/creating/


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads