Open In App

Moment.js moment.duration(Number) Method

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:




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

Output:

 

Example 2:




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

Output:

 

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

Article Tags :