Sometimes, we want to convert time interval given in seconds into more human readable form with JavaScript.
In this article, we’ll look at how to convert time interval given in seconds into more human readable form with JavaScript.
How to convert time interval given in seconds into more human readable form with JavaScript?
To convert time interval given in seconds into more human readable form with JavaScript, we can use the moment duration humanize
method.
For instance, we write
const duration = moment.duration(31536000);
console.log(duration.humanize());
to create a duration object by calling moment.duration
with a timestamp in milliseconds.
Then we call duration.humanize
to return a human readable string with the duration.
Conclusion
To convert time interval given in seconds into more human readable form with JavaScript, we can use the moment duration humanize
method.