0.3.0 • Published 7 years ago

human-readable-time v0.3.0

Weekly downloads
15
License
MIT
Repository
github
Last release
7 years ago

Convert Date to format given by pattern

Test status

Examples

var hrt = require('human-readable-time');

console.log(hrt(new Date(0), '%hh%:%mm%'));
// -> 00:00

console.log(hrt(new Date(0), 'Now is %YYYY% year'));
// -> Now is 1970 year

// Default pattern
console.log(hrt(new Date(0)));
// -> 00:00 01/01/1970

// Day/month string patterns
console.log(hrt(new Date(0), 'Today is %day%'));
// -> Today is Thursday

// Relative pattern
console.log(hrt(new Date(0), '%relative% ago'));
// -> 45 years ago

Currying is also supported!

var hrt = require('human-readable-time');

// You can use date, pattern and both in constructor
var clock = new hrt('hh:mm');

console.log(clock(new Date(0)));
// -> 00:00

Docs

SymbolMeaning
hhours
mminutes
sseconds
Dday of month
Mmonth
YYyear
dayday of week
monthmonth of year
relativerelative time
12hForce AM/PM position

Symbols can be used twice, it will add 0 if number less than 10, for example:

console.log(hrt(new Date(1000) '%s%'));
// -> 1

console.log(hrt(new Date(1000) '%ss%'));
// -> 01

But year can only be used in %YY% or %YYYY% variants.

Options

  • shortDay - Return first 3 letters of day for %day% pattern
  • shortTime - Return time in 12-hour format(you can specify %12h% option to force using 'PM'/'AM' in specific place)

License

MIT © Konstantin Azizov

0.3.0

7 years ago

0.2.4

8 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago

0.0.1

9 years ago