# formatdate-ts

> formate date by string

Latest version **1.1.0** (published 2023-09-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install formatdate-ts
pnpm add formatdate-ts
yarn add formatdate-ts
bun add formatdate-ts
```

## 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.0 |
| Published | 2023-09-23 |
| First published | 2023-09-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 27.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | gina |
| Maintainers | ginacccc |

## Links

- npm: https://www.npmjs.com/package/formatdate-ts
- Repository: https://github.com/gina10086/FormatDate
- Homepage: https://github.com/gina10086/FormatDate#readme
- Issues: https://github.com/gina10086/FormatDate/issues
- npm.io page: https://npm.io/package/formatdate-ts

## Recent versions

- 1.1.0 (latest) — 2023-09-23
- 1.0.9 — 2023-09-23
- 1.0.8 — 2023-09-23
- 1.0.7 — 2023-09-23
- 1.0.6 — 2023-09-23
- 1.0.5 — 2023-09-23
- 1.0.4 — 2023-09-23
- 1.0.3 — 2023-09-23
- 1.0.2 — 2023-09-06
- 1.0.1 — 2023-09-06
- 1.0.0 — 2023-09-06

## README

<!--
 * @Description: 
 * @Version: 2.0
 * @Author: Gina
 * @Date: 2023-09-07 01:25:17
 * @LastEditors: Gina
 * @LastEditTime: 2023-09-24 01:01:09
-->

## &#x20;安装



    npm i formatdate-ts



## 使用



```javascript
import formatDate from "formatdate-ts"
import type { Week } from "formatdate-ts"

const formatSetting = new formatDate() // ...args:Week[] 可加参数配置周相关显示默认为中文

const d = new Date()

formatSetting.format(d, 'yyyy-MM-dd w hh:mm:ss', 'zh') 
// 2023-09-07 周四 01:36:50
formatSetting.format(d, 'yyyy-MM-dd hh:mm:ss', 'zh') 
// 2023-09-07 01:36:50
formatSetting.format(d, 'yyyy') 
// 2023
formatSetting.format(d, 'yy') 
// 23
formatSetting.format(d, 'yyyy年M月dd w hh时mm分ss秒') 
// 2023年9月07日 周四 1时36分50秒
```



## &#x20;参数说明

### &#x20;formatSetting(...args\:Week\[] )



```javascript
new formatSetting({attr: 'zh', value: ['周日', '周一', '周二', '周三', '周四', '周五', '周六']}, {'en', value: ['Sun.', 'Mon.','Tues.','Wed.','Thur.','Fri.','Sat.']})
```

| 参数名  | 备注                                                                 |
| :--- | :----------------------------------------------------------------- |
| week | object, {attr, value};attr: string,语言名称， value: string\[], 每天周数的名称 |

### formatSetting.format(dateString, formatString, weekLan)



| 参数名          | 备注                                      |
| :----------- | :-------------------------------------- |
| dateString   | 必填，Date格式，需要格式化的Date数据                  |
| formatString | 必填，string，详情见下方format 格式说明              |
| weekLan      | 选填，string，默认‘zh’。设置的周的名称（Week.attr）解析类型 |

## format 格式说明

不论这个格式字符串长得什么样子，只替换对应的格式名，且根据格式名的长度进行转换；

```javascript
const d = new Date()
console.log(dateFormat(d, 'yY爱啥啥M月dd日 w h时m分s秒'))
//23爱啥啥9月7日 周四 2时24分19秒
```

| 格式名 | 值                                                                           |
| :-- | :-------------------------------------------------------------------------- |
| 年   | y/Y，连写代表长度，但是不能超Date.getFullYear()的长度，超出默认显示全部。如： yy ：23， yYy：023，yyyy：2023 |
| 月   | M，连写表示长度。如： MM：01， MMM：0001，M：1                                             |
| 日   | d/D，连写表示长度。如：d: 5, DD: 05                                                   |
| 周   | w/W, 具体看weekLan类型，默认为中文，如： 周一。                                              |
| 时   | h/H,连写表示长度。如：h: 5, HH: 05                                                   |
| 分   | m,连写表示长度。如：m: 5, m: 05                                                      |
| 秒   | s/S,连写表示长度。如：s: 5, SS: 05                                                   |

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