# date-utils-2020

> date utils 2020, format(date: Date, formatter: string)/toDate(a?: any)...

Latest version **1.1.2** (published 2024-05-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install date-utils-2020
pnpm add date-utils-2020
yarn add date-utils-2020
bun add date-utils-2020
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2024-05-25 |
| First published | 2020-12-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Capricorncd |
| Maintainers | capricorncd |
| Keywords | date-utils, date, utils, toDate, formatDate |

## Links

- npm: https://www.npmjs.com/package/date-utils-2020
- Repository: https://github.com/capricorncd/date-utils-2020
- Homepage: https://github.com/capricorncd/date-utils-2020#readme
- Issues: https://github.com/capricorncd/date-utils-2020/issues
- npm.io page: https://npm.io/package/date-utils-2020

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2024-05-25
- 1.1.1 — 2024-04-02
- 1.1.0 — 2023-01-14
- 1.0.3 — 2022-06-11
- 1.0.2 — 2021-08-01
- 1.0.1 — 2021-01-02
- 1.0.0 — 2021-01-01
- 0.0.2 — 2020-12-05
- 0.0.1 — 2020-12-04

## README

# 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`.

<p align="left">
  <a href="https://npmcharts.com/compare/date-utils-2020?minimal=true"><img src="https://img.shields.io/npm/dm/date-utils-2020.svg?sanitize=true" alt="Downloads"></a>
  <a href="https://www.npmjs.com/package/date-utils-2020"><img src="https://img.shields.io/npm/v/date-utils-2020.svg?sanitize=true" alt="Version"></a>
  <a href="https://www.npmjs.com/package/date-utils-2020"><img src="https://img.shields.io/npm/l/date-utils-2020.svg?sanitize=true" alt="License"></a>
</p>

```shell script
npm i -S date-utils-2020
# or
yarn add date-utils-2020
```

## Usage

```javascript
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
```

```javascript
// 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
```

```javascript
import { formatDate } from 'date-utils-2020'
constole.log(formatDate(new Date(), 'yyyy/MM/dd hh:mm:ss'))
```

## Methods

|Method|Parameters|Description|
|:--|:--|:--|
|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`

|format|meaning|Example|
|:--|:--|:--|
|yyyy/yy|year|`2021`/`21`|
|MM/M|month|`01`/`1`|
|dd/d|day|`01`/`1`|
|hh/h|hour|`01`/`1`|
|mm/m|minute|`01`/`1`|
|ss/s|second|`01`/`1`|
|w|week|`[0, 1, 2, 3, 4, 5, 6]`|
|W|week|`['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']`|
|a|am/pm|`am`|
|A|AM/PM|`AM`|
|g|GMT(Greenwich Mean Time)|`GMT+0900`|
|G|GMT(Greenwich Mean Time)|`GMT+0900 (Japan Standard Time)`, Safari `GMT+0900 (JST)`|

#### langPackage

|Props|Type|Description|
|:--|:--|:--|
|weeks|`string[]`|Example: `['日曜日', '月曜日', '火曜日', '水曜日', '木曜日', '金曜日', '土曜日']`, Default: `['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']`|

```javascript
const langPackage = {
  // ['日', '一', '二', '三', '四', '五', '六']
  weeks: ['日曜日', '月曜日', '火曜日', '水曜日', '木曜日', '金曜日', '土曜日']
}

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

---
_Source: https://npm.io/package/date-utils-2020 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
