# @jswork/simple-date-format

> A simple date format.

Latest version **1.0.6** (published 2025-11-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jswork/simple-date-format
pnpm add @jswork/simple-date-format
yarn add @jswork/simple-date-format
bun add @jswork/simple-date-format
```

## Health

**Score 60/100 (C)** — status: stable.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2025-11-05 |
| First published | 2023-08-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | afeiship, yujiao.luo |
| Keywords | dateformat, format, sdf, date, datetime, dayjs |

## Links

- npm: https://www.npmjs.com/package/@jswork/simple-date-format
- Homepage: https://js.work
- npm.io page: https://npm.io/package/@jswork/simple-date-format

## 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.0.6 (latest) — 2025-11-05
- 1.0.5 — 2023-10-30
- 1.0.4 — 2023-08-09
- 1.0.3 — 2023-08-09
- 1.0.2 — 2023-08-09
- 1.0.1 — 2023-08-09

## README

# simple-date-format
> A simple date format.

[![version][version-image]][version-url]
[![license][license-image]][license-url]
[![size][size-image]][size-url]
[![download][download-image]][download-url]

## installation
```shell
npm install @jswork/simple-date-format
```

## usage
```js
import sdf from '@jswork/simple-date-format';

// get current datetime:
const res1 = sdf('YYYY-MM-DD HH:mm:ss');
// 2020-01-01 12:12:12

// use format hooks
const res2 = sdf('date');
// 2020-01-01
```

## format hooks
```js
const FORMAT_HOOKS = {
  date: 'YYYY-MM-DD',
  datetime: 'YYYY-MM-DD HH:mm:ss',
  time: 'HH:mm:ss',
  month: 'YYYY-MM',
  dbdt: 'YYYYMMDD_HHmmss',
  fullday: 'YYYY/YYYY-MM/YYYY-MM-DD'
};
```

## formats

| format | Output           | Description          |
|--------|------------------|----------------------|
| YY     | 18               | 两位数的年份         |
| YYYY   | 2018             | 四位数的年份         |
| M      | 1-12             | 月份，从 1 开始      |
| MM     | 01-12            | 月份，两位数         |
| D      | 1-31             | 月份里的一天         |
| DD     | 01-31            | 月份里的一天，两位数 |


## license
Code released under [the MIT license](https://github.com/afeiship/simple-date-format/blob/master/LICENSE.txt).

[version-image]: https://img.shields.io/npm/v/@jswork/simple-date-format
[version-url]: https://npmjs.org/package/@jswork/simple-date-format

[license-image]: https://img.shields.io/npm/l/@jswork/simple-date-format
[license-url]: https://github.com/afeiship/simple-date-format/blob/master/LICENSE.txt

[size-image]: https://img.shields.io/bundlephobia/minzip/@jswork/simple-date-format
[size-url]: https://github.com/afeiship/simple-date-format/blob/master/dist/simple-date-format.min.js

[download-image]: https://img.shields.io/npm/dm/@jswork/simple-date-format
[download-url]: https://www.npmjs.com/package/@jswork/simple-date-format

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