Quartzite
Lightweight relative date/time formatter without external dependencies.
The formatter offers three styles - short
, medium
and long
.
Styles
Short | Medium | Long |
---|---|---|
now | Just now | Today, 18:00 |
25s | 25 seconds ago | Today, 18:00 |
30m | 30 minutes ago | Today, 17:30 |
18h | Today | Today 00:00 |
2d | Yesterday | Yesterday, 07:00 |
5d | November 7 | Thursday, November 7th |
Oct 8, 2018 | October 8, 2018 | October 8th, 2018 |
In 25s | In 25 seconds | Today, 10:00 |
In 30m | In 30 minutes | Today, 10:30 |
In 18h | Tomorrow | Tomorrow, 04:00 |
In 2d | Thursday | Thursday, 10:00 |
In 5d | November 17 | Sunday, November 17th |
Dec 16, 2020 | December 16, 2020 | December 16th, 2020 |
Installation
Using npm
$ npm install quartzite
Using cdn
Example
Importing as ES6 module
;
or using CommonJS
const quartzite = ;
Create date in the past
const date = ;const yesterday = quartzite;
Create date in the future
const date = ;const someday = quartzite;
Format date using medium
style
console; // Medium is the default optionconsole;
Format date using short
style
console;
Format date using long
style
console;
License
Licensed under the MIT License.