@knno/time
v1.3.1
Published
A simple date time helper toolkit.
Downloads
4
Readme
@knno/time
Description
A JavaScript time helper toolkit.
Installation
npm i @knno/time
How to use
- Import it
import time from "@knno/time";
- time.now()
console.log(time.now()); // get current time equal to new Date()
- time.moment()
console.log(time.moment(200000)); // get description string of a time duration: xxx days xxx hours xxx minutes xxx seconds
console.log(time.moment(200000), { maxUnit: "h" }); // biggest unit is hour
console.log(time.moment(200000), { minUnit: "m" }); // smallest unit is minute
// available unit are 'd', 'h', 'm', 's'
- time.interval()
console.log(time.interval("2019-1-1", "2020-2-10", "d"));
// available unit are 'd', 'h', 'm', 's', 'ms'
- time.add()
console.log(time.add("2019-1-1", 30, "d"));
// available unit are 'd', 'h', 'm', 's', 'ms'
- time.dayOfYear()
console.log(time.dayOfYear(new Date()));
- time.daysOfMonth()
console.log(time.daysOfMonth(new Date())); // get total days of month
- time.parse()
console.log(time.parse('2019-1-12'));
console.log(time.parse('2019-1-12 22:22:00'));
console.log(time.parse('2019-1-12T22:22:00+0800'));
console.log(time.parse('2019-1-12T22:22:00Z'));
console.log(time.parse('1/1/2020'));
console.log(time.parse('Jan 1, 2020'));
......
// if some format cannot be auto detect, you can specify format manually
console.log(time.parse('2019年5月31日 20:08:30', 'yyyy年M月d日 hh:mm:ss'));
- time.format()
console.log(time.format(time.now()); // use default format ISO8601 to convert to string
console.log(time.format(time.now(), 'yyyy年MM月dd日'); // use custom format to convert
......
That's all