1.1.1 • Published 3 years ago

thor-time v1.1.1

Weekly downloads
3
License
MIT
Repository
-
Last release
3 years ago

thor-time

Description

A JavaScript time helper toolkit.

Installation

npm i thor-time

How to use

  1. Import it
import time from "thor-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.distance()
console.log(time.distance("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.1.1

3 years ago

1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago