Prettytime
Prettytime is a micro library for converting millis (e.g. prettytime(2342)
) into a human friendly format (e.g. 2.3 seconds
).
Install
$ npm install prettytime
Usage
var prettytime = require('prettytime');
var now = Date.now();
...
prettytime(now - Date.now());
Examples
prettytime(100);
prettytime(1000);
prettytime(5000);
prettytime(60000);
prettytime(3600000);
Options
options.decimals
Allows you to set the decimal limit of the returned values, always rounded to the nearest significant decimal
Examples
prettytime(1236, { decimals: 1 });
prettytime(1236, { decimals: 2 });
options.short
Converts the time type to a short string.
Full | Short |
---|
year | y |
month | mo |
day | d |
hour | h |
minute | m |
second | s |
ms | ms |
Examples
prettytime(100, { short: true});
prettytime(1000, { short: true});
prettytime(60000, { short: true});
prettytime(3600000, { short: true});
License
MIT © Jason Wilson