All Projects → jonschlinkert → Pretty Time

jonschlinkert / Pretty Time

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

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Pretty Time

Gostradamus
Gostradamus: Better DateTimes for Go 🕰️
Stars: ✭ 148 (+236.36%)
Mutual labels:  time, format
Time Stamp
Get a formatted timestamp. Used in gulp, assemble, generate, and many others.
Stars: ✭ 104 (+136.36%)
Mutual labels:  time, format
Tinydate
A tiny (349B) reusable date formatter. Extremely fast!
Stars: ✭ 990 (+2150%)
Mutual labels:  time, format
date-php
这是一个Javascript模仿PHP日期时间格式化函数,使用方法和PHP非常类似,有丰富的模板字符,并在原来的基础上增加了一些模板字符。 This is a date function that implement PHP in Javascript. It is very similar to PHP, has rich template characters, and enhances some template characters on the basis of the original.
Stars: ✭ 24 (-45.45%)
Mutual labels:  time, format
timelite
String date and time utilities 🕙
Stars: ✭ 17 (-61.36%)
Mutual labels:  time, format
jodaTime
Format and Parse date and time with joda layout
Stars: ✭ 67 (+52.27%)
Mutual labels:  time, format
Date And Time
A Minimalist DateTime utility for Node.js and the browser
Stars: ✭ 99 (+125%)
Mutual labels:  time, format
lit-date
Light-weight, faster datetime formatter for modern browsers.
Stars: ✭ 33 (-25%)
Mutual labels:  time, format
vue-translated
Internationalization (i18n) and localization (l10n) library for Vue.js v2.
Stars: ✭ 19 (-56.82%)
Mutual labels:  time, format
Translatedjs
Internationalization and localization for JavaScript and Node.js
Stars: ✭ 17 (-61.36%)
Mutual labels:  time, format
Time
Windows tool for measuring command/program execution speed
Stars: ✭ 21 (-52.27%)
Mutual labels:  time
Diff Table
Stars: ✭ 21 (-52.27%)
Mutual labels:  diff
Deepdiff
Deep Difference and search of any Python object/data.
Stars: ✭ 985 (+2138.64%)
Mutual labels:  diff
Vim Gitgutter
A Vim plugin which shows git diff markers in the sign column and stages/previews/undoes hunks and partial hunks.
Stars: ✭ 7,364 (+16636.36%)
Mutual labels:  diff
Protodate
Better Javascript Dates.
Stars: ✭ 14 (-68.18%)
Mutual labels:  format
Period
Complex period comparisons
Stars: ✭ 1,001 (+2175%)
Mutual labels:  time
Pytorch Forecasting
Time series forecasting with PyTorch
Stars: ✭ 849 (+1829.55%)
Mutual labels:  time
Xformat
Multi-syntax printf
Stars: ✭ 8 (-81.82%)
Mutual labels:  format
Covid19 Brazil Timeseries
Data collection to analyze the dissemination of COVID-19 through Brazilian states. Contributions are welcome.
Stars: ✭ 43 (-2.27%)
Mutual labels:  time
Letnice
A simple javascript calendar
Stars: ✭ 41 (-6.82%)
Mutual labels:  time

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 ❤️ and support.

Install

Install with npm:

$ npm install --save pretty-time

Usage

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

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

API

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).

Examples:

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.

Examples

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

About

Contributing

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 readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md 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

Contributors

Commits Contributor
14 jonschlinkert
5 doowb

Author

Jon Schlinkert

License

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


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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].