2.0.1 • Published 2 years ago

@jayson991/date-time-utils v2.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

date-time-utils

A Util Library For Date && Time Operations.

Usage

Installation

$ npm i -S @jayson991/date-time-utils

Use In CommonJS(Like Node.js)

const {getWeek, getCalendar} = require('@jayson991/date-time-utils')

console.log(JSON.stringify(getCalendar('2020-02-01', '2020-02-03')))

console.log(getWeek('2020-02-01'))
console.log(getWeek('2020/02/01'))
console.log(getWeek(1580515200000))

getCalendar Output

[
  { "year": 2020, "month": 1, "day": 1, "week": 6 },
  { "year": 2020, "month": 1, "day": 2, "week": 0 },
  { "year": 2020, "month": 1, "day": 3, "week": 1 }
]

getWeek Output

6 // console.log(getWeek('2020-02-01'))
6 // console.log(getWeek('2020/02/01'))
6 // console.log(getWeek(1580515200000))

Use In ES6 Module(Like Vue | React | Angular Projects)

import { getCalendar, getWeek } from '@jayson991/date-time-utils'

console.log(JSON.stringify(getCalendar('2020-02-01', '2020-02-03')))

console.log(getWeek('2020-02-01'))
console.log(getWeek('2020/02/01'))
console.log(getWeek(1580515200000))

getCalendar Output

[
  { "year": 2020, "month": 1, "day": 1, "week": 6 },
  { "year": 2020, "month": 1, "day": 2, "week": 0 },
  { "year": 2020, "month": 1, "day": 3, "week": 1 }
]

getWeek Output

6 // console.log(getWeek('2020-02-01'))
6 // console.log(getWeek('2020/02/01'))
6 // console.log(getWeek(1580515200000))

Explanation

fieldformation
month0 -> January, 1 -> February, 2 -> March...
week0 -> Sunday, 1 -> Monday, 2 -> Tuesday...

All Functions

Please see more examples in test folder, for it is not just like the below provided.

Including getCalendar & getWeek. getDays is for the day difference of two dates, getHours is for the hour difference of two dates, getMinutes is for the minute difference of two dates, getSeconds is for the second difference of two dates, these four functions can be combined together to get the difference of two dates.

NameOutput Result
addPrefixaddPrefix(1) -> '01'
deletePrefixdeletePrefix('01') -> 1
getMonthWeekgetMonthWeek(2020, 2, 7) -> 2
getYearWeekgetYearWeek(2020, 2, 10) -> 7
getDaysgetDays('2020-02-01', '2020-02-03') -> 2
getHoursgetHours('2020-02-01T10:45', '2020-02-03T12:15') -> 1
getMinutesgetMinutes('2020-02-01T10:45', '2020-02-03T12:15') -> 30
getSecondsgetSeconds('2020-02-01T10:45:20', '2020-02-03T12:15:50') -> 30
2.0.1

2 years ago

2.0.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.1

3 years ago