@darkwolf/time.mjs

1.0.4 • Public • Published

Time

Install

ECMAScript (Node.js v12.x LTS or higher)

npm i --save @darkwolf/time.mjs

CommonJS (Node.js v10.x LTS or higher)

npm i --save @darkwolf/time.cjs

Using

// ECMAScript
import Time, { Timestamp, UnixTimestamp } from '@darkwolf/time.mjs'

// CommonJS
const Time = require('@darkwolf/time.cjs')
const { Timestamp, UnixTimestamp } = Time

Time.ms('23h 59min 59sec') // => 86399000
Time.sec('-23h 59min 59sec') // => -86399
Time.now() // => Current timestamp in milliseconds: 2147483000647
Time.unix() // => Current Unix timestamp in seconds: 2147483000
Time.unix({millis: true}) // => Current Unix timestamp in seconds with millisecond fraction: 2147483000.647
const timestamp = Time.timestamp()
timestamp.value // => Current timestamp in milliseconds: 2147483000647
const unixTimestamp = Time.unixTimestamp()
unixTimestamp.value // => Current Unix timestamp in seconds: 2147483000
const date = new Date('2021-01-01')
const unix = new UnixTimestamp(date).add('23h 59min 59sec')
unix.toString() // => '2021-01-01T23:59:59Z'
unix
  .add('1 сек')
  .subtract('.5 дня')
unix.toString() // => '2021-01-01T12:00:00Z'
const other = unix
  .clone()
  .add('12 часов')
other.toString() // => '2021-01-02T00:00:00Z'
const diff = other - unix // => 43200

API Documentation

Contact Me

GitHub: @PavelWolfDark

Telegram: @PavelWolfDark

Email: PavelWolfDark@gmail.com

Package Sidebar

Install

npm i @darkwolf/time.mjs

Weekly Downloads

2

Version

1.0.4

License

MIT

Unpacked Size

19.8 kB

Total Files

10

Last publish

Collaborators

  • pavelwolfdark