Easily format the time from node.js `process.hrtime`. Works with timescales ranging from weeks to nanoseconds.

Usage no npm install needed!

<script type="module">
  import prettyTime from '';


pretty-time NPM version NPM monthly downloads NPM total downloads Linux Build Status

Easily format the time from node.js process.hrtime. Works with timescales ranging from weeks to nanoseconds.

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.


Install with npm:

$ npm install --save pretty-time


var pretty = require('pretty-time');

var start = process.hrtime();
var time = process.hrtime(start);
//=> 3μs


By default, when no time increment is given as the second argument, the closest timescale is used (e.g. most granular without being less than zero).


pretty([1200708, 795428088]);
//=> '2w'

pretty([800708, 795428088]);
//=> '1w'

pretty([400708, 795428088]);
//=> '5d'

pretty([70708, 795428088]);
//=> '20h'

pretty([12708, 795428088]);
//=> '4h'

pretty([3708, 795428088]);
//=> '1h'

pretty([208, 795428088]);
//=> '3m'

pretty([20, 795428088]);
//=> '21s'

pretty([0, 795428088]);
//=> '795ms'

pretty([0, 000428088]);
//=> '428μs'

pretty([0, 000000088]);
//=> '88ns'

pretty([0, 000000018]);
//=> '18ns'

Minimum time increment

(All of the following examples use [6740, 795428088] as the hrtime array.)

This value is passed as the second argument and determines how granular to make the time.


pretty(time, 'h');
//=> '2h'

pretty(time, 'm');
//=> '1h 52m'

pretty(time, 's');
//=> '1h 52m 21s'

Valid time increments

Any of the following may be used:

  • ns | nano | nanosecond | nanoseconds
  • μs | micro | microsecond | microseconds
  • ms | milli | millisecond | milliseconds
  • s | sec | second | seconds
  • m | min | minute | minutes
  • h | hr | hour | hours
  • d | day | days
  • w | wk | week | weeks



Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test
Building docs

(This project's is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Related projects

You might also be interested in these projects:

  • o-clock: Simple javascript utility for displaying the time in 12-hour clock format. | homepage
  • seconds: Get the number of seconds for a minute, hour, day and week. | homepage
  • time-stamp: Get a formatted timestamp. | homepage
  • timescale: Convert from one time scale to another. Nanosecond is the most atomic unit, week is… more | homepage
  • week: Get the current week number. | homepage
  • weekday: Get the name and number of the current weekday. Or get the name of the… more | homepage
  • year: Simple utility to get the current year with 2 or 4 digits. | homepage


Commits Contributor
14 jonschlinkert
5 doowb


Jon Schlinkert


Copyright © 2018, Jon Schlinkert. Released under the MIT License.

This file was generated by verb-generate-readme, v0.6.0, on July 12, 2018.