GitHub - lukeed/tinydate: A tiny (340B) reusable date formatter. Extremely fast!
source link: https://github.com/lukeed/tinydate
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
readme.md
tinydate
A tiny (340B) reusable date formatter. Extremely fast!
Inspired by tinytime
, this module returns a "render" function that efficiently re-render your deconstructed template. This allows for incredibly performant results!
However, please notice that this only provides a limited subset of Date methods.
If you need more, tinytime
or date-fns
are great alternatives!
Install
$ npm install --save tinydate
Usage
const tinydate = require('tinydate'); const fooDate = new Date('5/1/2017, 4:30:09 PM'); const stamp = tinydate('Current time: [{HH}:{mm}:{ss}]'); stamp(fooDate); //=> Current time: [16:30:09] stamp(); //=> Current time: [17:09:34]
API
tinydate(pattern)(date)
pattern
Type: string
The template pattern to be parsed.
date
Type: Date
Default: new Date()
The date from which to retrieve values. Defaults to current datetime.
Patterns
{YYYY}
: full year; eg: 2017{YY}
: short year; eg: 17{MM}
: month; eg: 04{DD}
: day; eg: 01{HH}
: hours; eg: 06 (24h){mm}
: minutes; eg: 59{ss}
: seconds; eg: 09{fff}
: milliseconds; eg: 555
Benchmarks
# Node v10.13.0
tinydate x 160,834,214 ops/sec ±0.21% (96 runs sampled)
tinytime x 44,602,162 ops/sec ±0.34% (97 runs sampled)
time-stamp x 888,153 ops/sec ±1.27% (86 runs sampled)
License
MIT © Luke Edwards
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK