Horje
Moment.js Duration Format Plugin

The Duration plugin makes it possible to add a lot of formatting options to Moment Durations of the Moment.js JavaScript date library. This will make it possible to describe a duration as required by the user.

Write the below command in the terminal to install Duration Format Plugin:

npm install moment-duration-format

 

The following are some of the functions in this plugin:

  • format

The below examples will help to understand some of the methods of the Duration Format Plugin.

Example 1:

Javascript

import moment from 'moment';
import format from 'moment-duration-format';
  
let duration = moment.duration(2, 'weeks');
console.log(duration.format("h:mm"));

Output:

 

Example 2:

Javascript

import moment from 'moment';
import format from 'moment-duration-format';
  
let duration = moment.duration({
    seconds: 3,
    minutes: 3,
    hours: 3,
    days: 3,
    weeks: 3,
    months: '3',
    years: '3'
});
console.log(duration.format());

Output:

 

Reference: https://momentjs.com/docs/#/plugins/duration-format/




Reffered: https://www.geeksforgeeks.org


Node.js

Related
Moment.js Twix Plugin Moment.js Twix Plugin
Moment.js Recur Plugin Moment.js Recur Plugin
How to build Video Streaming Application using Node.js ? How to build Video Streaming Application using Node.js ?
How to Build Note Taking Application using Node.js? How to Build Note Taking Application using Node.js?
How to restart Node.js application when uncaught exception happen ? How to restart Node.js application when uncaught exception happen ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
11