Skip to content

A micro library for converting millis into a human friendly format.

License

Notifications You must be signed in to change notification settings

scurker/prettytime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prettytime Build Status npm

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());
// => 2.3 seconds

Examples

prettytime(100);     // => 100 ms
prettytime(1000);    // => 1 second
prettytime(5000);    // => 5 seconds
prettytime(60000);   // => 1 minute
prettytime(3600000); // => 1 hour

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 }); // => 1.2 seconds
prettytime(1236, { decimals: 2 }); // => 1.24 seconds

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 });     // => 100 ms
prettytime(1000, { short: true });    // => 1 s
prettytime(60000, { short: true });   // => 1 m
prettytime(3600000, { short: true }); // => 1 h

License

MIT © Jason Wilson

About

A micro library for converting millis into a human friendly format.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published