Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Error : moment.duration is not a function

Tags:

node.js

npm

I am trying to convert seconds in HH:MM:SS format. I am getting an error moment.duration is not a function.

var moment = require("moment-duration-format");

moment.duration(123, "seconds").format("hh:mm:ss");

like image 558
Sumit Sarkar Avatar asked Mar 31 '17 20:03

Sumit Sarkar


People also ask

How do you use moment duration?

var duration = moment. duration("09:30"); var str = moment(duration. _data). format("HH:mm");

What is the use of moment in JavaScript?

Moment JS allows displaying of date as per localization and in human readable format. You can use MomentJS inside a browser using the script method. It is also available with Node. js and can be installed using npm.


1 Answers

The moment-duration-format plugin depends on moment, so you should import/require it first:

var moment = require("moment")
require("moment-duration-format");

moment.duration(123, "seconds").format("hh:mm:ss");
like image 183
helb Avatar answered Oct 09 '22 12:10

helb