This is a
playground to test code. It runs a full
Node.js environment and already has all of
npm’s 400,000 packages pre-installed, including
readable-seconds with all
npm packages installed. Try it out:
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.
Package to convert seconds into a readable format.
$ npm install readable-seconds --save
If a second argument is not provided then all units are returned.
const readableSeconds = require("readable-seconds"); console.log(readableSeconds(3690)); // 1 hour, 1 minute and 30 seconds
An optional second argument can be used to limit the maximum number of units returned.
console.log(readableSeconds(3690, 2)); // 1 hour and 1 minute
This module converts seconds into years, days, hours, minutes and seconds. A human-readable string is returned. Units with values of 0 are omitted and all the values returned are followed by the relevant unit type which will be appropriately singular or plural depending on the value. The units are separated by commas if there are more than 2 and the last value is preceded by the word "and".
An optional second argument can be provided to limit the number of units returned to the 2 largest units. This can be useful when dealing with large numbers of units where the smaller units are of less significance, as in the following example:
console.log(readableSeconds(31622490)); // 1 year, 1 day, 1 minute and 30 seconds console.log(readableSeconds(31622490, 2)); // 1 year and 1 day