0.7.7 • Published 6 months ago

tea-date v0.7.7

Weekly downloads
-
License
-
Repository
-
Last release
6 months ago

简体中文 | English

tea-date

A minimalist javascript date-handling library

install

pnpm install tea-date
npm install tea-date

API

// Get current date
new TDate().format('YYYY-MM-DD') 

Constructor and time formatting

import { TDate } from 'tea-date'

// Time as string
new TDate('2023').format('YYYY-MM-DD') // 2023-01-01
new TDate('2023-11').format('YYYY-MM-DD') // 2023-11-01
new TDate('2023-11-06').format('YYYY-MM') // 2023-11
new TDate('2023-11-6').format('YYYY-MM-DD') // 2023-11-06
new TDate('2023-11-6').format('YYYY-MM-DD HH:mm:ss') // 2023-11-06 00:00:00
// Time as timestamp (milliseconds)
new TDate(1699252941321).format('YYYY-MM-DD') // 2023-11-06
new TDate(1699252941321).format('YYYY-MM-D') // 2023-11-6
new TDate(1672987341000).format('YYYY-MM-D') // 2023-01-6
new TDate(1672987341000).format('YYYY-M-D') // 2023-1-6
new TDate(1672987341000).format('YYYY-M-D HH:mm:ss') // 2023-1-6 14:42:21

Get the time before or after

import { TDate } from 'tea-date'

new TDate('2023-01-26').daysAfter(2) // ['2023-01-27', '2023-01-28']
new TDate('2023-01-26').daysBefore(2) // ['2023-01-25', '2023-01-24']
new TDate('2023-01-26').weeksAfter(2) // ['2023-02-02', '2023-02-09']
new TDate('2023-01-26').weeksBefore(2) // ['2023-01-19', '2023-01-12']
new TDate('2023-01-26').monthsAfter(2) // ['2023-02', '2023-03']
new TDate('2023-01-26').monthsBefore(2) // ['2022-12', '2022-11']
new TDate('2023-01-26').yearsAfter(2) // ['2024', '2025']
new TDate('2023-01-26').yearsBefore(2) // ['2022', '2021']

Transition time

import { TDate, DATE_SHORT_NAME} from 'tea-date'
new TDate('2023-01-06').change(10, DATE_SHORT_NAME.Day).change(1, DATE_SHORT_NAME.M).format('YYYY-MM-DD') // 2023-02-16
new TDate('2023-01-06').change(-2, DATE_SHORT_NAME.D).change(-1, DATE_SHORT_NAME.Month).format('YYYY-MM-DD') // 2022-12-04

Get the first and last day of the month

new TDate('2023-01-26').getMonthFirstDay() // 2023-01-01
new TDate('2023-01-26').getMonthLastDay() // 2023-01-31
0.7.7

6 months ago

0.7.6

6 months ago

0.7.5

6 months ago

0.7.4

6 months ago

0.7.3

6 months ago

0.7.2

6 months ago

0.7.1

6 months ago

0.6.4

6 months ago

0.6.3

6 months ago

0.6.1

6 months ago

0.5.1

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago