1.3.1 • Published 5 months ago

@knno/time v1.3.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

@knno/time

Description

A JavaScript time helper toolkit.

Installation

npm i @knno/time

How to use

  1. Import it
import time from "@knno/time";
  1. time.now()
console.log(time.now()); // get current time equal to new Date()
  1. 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'
  1. time.interval()
console.log(time.interval("2019-1-1", "2020-2-10", "d"));
// available unit are 'd', 'h', 'm', 's', 'ms'
  1. time.add()
console.log(time.add("2019-1-1", 30, "d"));
// available unit are 'd', 'h', 'm', 's', 'ms'
  1. time.dayOfYear()
console.log(time.dayOfYear(new Date()));
  1. time.daysOfMonth()
console.log(time.daysOfMonth(new Date())); // get total days of month
  1. 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'));
  1. 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

1.2.0

7 months ago

1.3.1

5 months ago

1.3.0

6 months ago

1.1.1

1 year ago