# time_escape

> 提供格式化时间,HTML标签转换的功能

Latest version **1.1.2** (published 2026-06-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install time_escape
pnpm add time_escape
yarn add time_escape
bun add time_escape
```

## Health

**Score 45/100 (D)** — status: active.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2026-06-10 |
| First published | 2022-03-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | renlmingj |
| Keywords | renlmingj, dateFormat, escape |

## Links

- npm: https://www.npmjs.com/package/time_escape
- npm.io page: https://npm.io/package/time_escape

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2026-06-10
- 1.1.1 — 2026-06-10
- 1.1.0 — 2026-06-10
- 1.0.0 — 2022-03-16

## README

### 安装
```
npm install time_escape
```

### 导入
```js
const timeEscape = require('time_escape')
```

### 格式化时间
```js
// 调用 dateFormat 方法对时间进行格式化
const dtStr = timeEscape.dateFormat(new Date());
// 将格式化后的时间输出到控制台  2022-03-17 00:08:30
console.log(dtStr);
```

#### 支持的输入类型
```js
// 支持数字时间戳
timeEscape.dateFormat(1620000000000);  // "2021-05-03 15:20:00"

// 支持字符串时间戳
timeEscape.dateFormat("1620000000000");  // "2021-05-03 15:20:00"

// 支持日期字符串
timeEscape.dateFormat("2024-01-15");  // "2024-01-15 00:00:00"

// 支持 Date 对象
timeEscape.dateFormat(new Date());  // 当前时间
```

#### 自定义输出格式
```js
// 使用第二个参数指定输出格式
timeEscape.dateFormat(new Date(), "YYYY-MM-DD");  // "2024-01-15"
timeEscape.dateFormat(new Date(), "YYYY年MM月DD日");  // "2024年01月15日"
timeEscape.dateFormat(new Date(), "HH:mm:ss");  // "10:30:45"
```

#### 支持的格式符
| 格式符 | 说明 | 示例 |
|--------|------|------|
| `YYYY` | 4位年份 | 2024 |
| `YY` | 2位年份 | 24 |
| `MM` | 补零月份 | 01-12 |
| `M` | 不补零月份 | 1-12 |
| `DD` | 补零日期 | 01-31 |
| `D` | 不补零日期 | 1-31 |
| `HH` | 补零小时 | 00-23 |
| `H` | 不补零小时 | 0-23 |
| `mm` | 补零分钟 | 00-59 |
| `m` | 不补零分钟 | 0-59 |
| `ss` | 补零秒 | 00-59 |
| `s` | 不补零秒 | 0-59 |
| `W` | 星期（单字） | 日/一/二 |
| `WW` | 星期（周） | 周日/周一/周二 |
| `WWW` | 星期（完整） | 星期日/星期一 |

#### 预设格式示例
```js
// 默认格式
timeEscape.dateFormat(new Date())  // "YYYY-MM-DD HH:mm:ss"

// 常用格式
timeEscape.dateFormat(new Date(), "YYYY-MM-DD")           // "2024-01-15"
timeEscape.dateFormat(new Date(), "YYYY/MM/DD")           // "2024/01/15"
timeEscape.dateFormat(new Date(), "MM/DD/YYYY")           // "01/15/2024"
timeEscape.dateFormat(new Date(), "YYYY年MM月DD日")         // "2024年01月15日"
timeEscape.dateFormat(new Date(), "YYYY年MM月DD日 HH时mm分ss秒") // "2024年01月15日 10时30分45秒"
timeEscape.dateFormat(new Date(), "YYYY-MM-DD HH:mm:ss W")  // "2024-01-15 10:30:45 二"
timeEscape.dateFormat(new Date(), "YYYY-MM-DD HH:mm:ss WW")  // "2024-01-15 10:30:45 周二"
timeEscape.dateFormat(new Date(), "YYYY-MM-DD HH:mm:ss WWW") // "2024-01-15 10:30:45 星期二"
```

### 转义 html 特殊字符
```js
// 待转换的 html 字符串
const htmlStr = '<h1>123456</h1>';
// 调用 htmlEscape 方法进行转换
const str = timeEscape.htmlEscape(htmlStr);
// 将格转换后的结果输出到控制台  &lt;h1&gt;232456&lt;/h1&gt;
console.log(str);
```

### 还原 html 特殊字符
```js
// 待还原的常量为 str
// 调用 htmlUnEscape 方法进行还原
const str2 = timeEscape.htmlUnEscape(b);
// 将还原后的结果输出到控制台  <h1>232456</h1>
console.log(str2);
```

### 有任何问题请联系我

renlmingj@qq.com

### 开源协议

ISC

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