A tiny time format lib
npm i tickjs -S
As CommonJS module
const Tick = require('tickjs');
const today = new Tick().format('YYYY-MM-DD');
As ES module
import Tick from 'tickjs';
const today = new Tick().format('YYYY-MM-DD');
Paramters
Tick inherit Date instance. So the paramters are the same as Date instance.
Methods
- Arguments:
- {string} template
- Usage:
Format a time template string.
new Tick().format('YYYY-MM-DD'); // YYYY -> Year // WW -> Week // MM -> Month // DD -> Day // Md -> Month(no zero on head) // Dd -> Day(no zero on head) // hh -> Hour // mm -> Minute // ss -> Second
- Usage:
Get the object of time.
new Tick().getMap(); // { year: '..', month: '..', day: '..', ... }
- Usage:
Get the description of time difference.
new Tick(Date.now() - 20000000).getDiff(); // 5小时前
- Arguments:
- {string} timeOffset
- Usage:
calculate time offset.
new Tick('2018-05-01').offset('1Y'); // '2019-05-01T00:00:00.000Z' new Tick('2018-05-01').offset('-1Y1M'); // '2017-04-01T00:00:00.000Z'
- Arguments:
- {string} time
- Usage:
compare time.
new Tick('2018-05-01').isBefore('2018-06-01'); // true
- Arguments:
- {string} time
- Usage:
compare time.
new Tick('2018-05-01').isAfter('2018-04-01'); // true
- Arguments:
- {string} time
- Usage:
compare time.
new Tick('2018-05-01').isEqual('2018-05-01'); // true
- Arguments:
- {string} year
- Usage:
check year is leap year.
Tick.isLeapYear(2018) // false
MIT