tickjs

0.1.1 • Public • Published

Tick

A tiny time format lib

install

npm i tickjs -S

Usage

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');

Documentation

Paramters

Tick inherit Date instance. So the paramters are the same as Date instance.

Methods

format(template)
  • 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
getMap()
  • Usage: Get the object of time.
    new Tick().getMap(); // { year: '..', month: '..', day: '..', ... }
getDiff()
  • Usage: Get the description of time difference.
    new Tick(Date.now() - 20000000).getDiff(); // 5小时前
offset(timeOffset)
  • 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'
isBefore(time)
  • Arguments:
    • {string} time
  • Usage: compare time.
    new Tick('2018-05-01').isBefore('2018-06-01'); // true
isAfter(time)
  • Arguments:
    • {string} time
  • Usage: compare time.
    new Tick('2018-05-01').isAfter('2018-04-01'); // true
isEqual(time)
  • Arguments:
    • {string} time
  • Usage: compare time.
    new Tick('2018-05-01').isEqual('2018-05-01'); // true
isLeapYear(year)
  • Arguments:
    • {string} year
  • Usage: check year is leap year.
    Tick.isLeapYear(2018) // false

LICENSE

MIT

Readme

Keywords

Package Sidebar

Install

npm i tickjs

Weekly Downloads

5

Version

0.1.1

License

MIT

Unpacked Size

28.3 kB

Total Files

11

Last publish

Collaborators

  • daben