1.1.1 • Published 1 month ago

date-utils-2020 v1.1.1

Weekly downloads
25
License
MIT
Repository
github
Last release
1 month ago

date-utils-2020

date utils 2020, format(s: any, formatter: string)/toDate(s?: any)...

Note:

When the parameter s is a string: when it is a string of yyyyMMdd/yyyyMM/yyyy, it is processed as yyyyMMdd/yyyyMM01/yyyy0101, and other string numbers are processed as a timestamp.

npm i -S date-utils-2020
# or
yarn add date-utils-2020

Usage

import { formatDate, toDate } from 'date-utils-2020'

const date = toDate('2020-12-04')
console.log(date) 
// Fri Dec 04 2020 09:00:00 GMT+0900 (Japan Standard Time)

const result = formatDate('2020-12-04', 'yyyy/MM/dd W')
console.log(result)
// 2020/12/04 Fri
// node.js
const { formatDate } = require('date-utils-2020')

const result = formatDate(new Date(), 'yyyy/MM/dd hh:mm:ss')
console.log(result)
// 2020/12/05 16:07:43

// timestamp
console.log(formatDate(20210101, 'yyyy-MM-dd hh:mm:ss'))
// 1970-01-01 14:36:50

// yyyyMMdd
console.log(formatDate('20210101', 'yyyy-MM-dd hh:mm:ss g'))
// 2021-01-01 00:00:00 GMT+0900
import { formatDate } from 'date-utils-2020'
constole.log(formatDate(new Date(), 'yyyy/MM/dd hh:mm:ss'))

Methods

MethodParametersDescription
formatDate(date: any, format: string, langPackage?: ILangPackage)return string
toDate(s: any)return Date or null. When the parameter s is a string: when it is a string of yyyyMMdd/yyyyMM/yyyy, it is processed as yyyyMMdd/yyyyMM01/yyyy0101, and other string numbers are processed as a timestamp.

format

Date Formats, Example yyyy-MM-dd hh:mm:ss W => 2021-01-01 01:01:01 Fri

formatmeaningExample
yyyy/yyyear2021/21
MM/Mmonth01/1
dd/dday01/1
hh/hhour01/1
mm/mminute01/1
ss/ssecond01/1
wweek[0, 1, 2, 3, 4, 5, 6]
Wweek['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
aam/pmam
AAM/PMAM
gGMT(Greenwich Mean Time)GMT+0900
GGMT(Greenwich Mean Time)GMT+0900 (Japan Standard Time), Safari GMT+0900 (JST)

langPackage

PropsTypeDescription
weeksstring[]Example: ['日曜日', '月曜日', '火曜日', '水曜日', '木曜日', '金曜日', '土曜日'], Default: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
const langPackage = {
  // ['日', '一', '二', '三', '四', '五', '六']
  weeks: ['日曜日', '月曜日', '火曜日', '水曜日', '木曜日', '金曜日', '土曜日']
}

formatDate(new Date(), 'yyyy/MM/dd(W) hh:mm:ss', langPackage)
// 2020/12/05(土曜日) 12:22:52
1.1.1

1 month ago

1.1.0

1 year ago

1.0.3

2 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago