# date-to-iso-8601-string

> Presents a JavaScript `Date` as a string in [ISO 8601 format](https://www.loc.gov/standards/datetime/iso-tc154-wg5_n0038_iso_wd_8601-1_2016-02-16.pdf), with support for the Extended (`YYYY-MM-DD`) and Basic (`YYYYMMDD`) variants

Latest version **2.0.0** (published 2022-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install date-to-iso-8601-string
pnpm add date-to-iso-8601-string
yarn add date-to-iso-8601-string
bun add date-to-iso-8601-string
```

## 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 | 2.0.0 |
| Published | 2022-04-27 |
| First published | 2022-04-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Caffeine Software Ltd |
| Maintainers | timrogers |
| Keywords | date, iso, iso8601, iso-8601 |

## Links

- npm: https://www.npmjs.com/package/date-to-iso-8601-string
- Homepage: https://github.com/caffeinesoftware/date-to-iso-8601-string
- npm.io page: https://npm.io/package/date-to-iso-8601-string

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

- 2.0.0 (latest) — 2022-04-27
- 1.0.0 — 2022-04-02
- 0.0.1-security — 2022-04-01

## README

# date-to-iso-8601-string

Presents a JavaScript `Date` as a string in [ISO 8601 format](https://www.loc.gov/standards/datetime/iso-tc154-wg5_n0038_iso_wd_8601-1_2016-02-16.pdf), with support for the Extended (`YYYY-MM-DD`) and Basic (`YYYYMMDD`) variants.

Note that this module uses the "local date" in the time zone of the machine, rather than the UTC dfate.

This package includes TypeScript types.

## Installation

```bash
# With npm
npm install --save date-to-iso-8601-string

# With Yarn
yarn add date-to-iso-8601-string
```

## Usage

### Presenting a Date using the more common "Extended" (`YYYY-MM-DD` format)

```js
// You can also import as a CommonJS module using `require`
import { dateToISO8601String } from 'date-to-iso-8601-string';

const date = new Date('2023-01-01');
dateToISO8601String(date);
//=> '2023-01-01'
```

### Presenting a Date using the less common "Basic" (`YYYY-MM-DD` format)

```js
import { dateToISO8601String, ISO8601DateFormat } from 'date-to-iso-8601-string';

const date = new Date('2023-01-01');
dateToISO8601String(date, ISO8601DateFormat.Basic);
//=> '20230101'
```

## Development

- This library code in `src/` is written with Typescript.
  - You can compile it to native JavaScript module form (`dist/esm`) and CommonJS form (`dist/commonjs`) by running `npm run build`.
  - The code is automatically built before pushing to `npm` thanks to a `prepublish` hook.
- Tests are implemented using Jest.
  - You can run the tests with `npm run test`.
- Linting (including code formatting) is enforced with ESLint, augmented by Prettier.
  - You can check your code with `npm run lint`, and automatically fix many failures with `npm run lint-and-fix`.

The compilation, testing and build process are automatically run on pushed code using GitHub Actions.

## With thanks to:

The following blog posts were very helpful for putting this - my first ever `npm` package - together!:

- https://blog.logrocket.com/publishing-node-modules-typescript-es-modules/ (@jackfranklin)
- https://blog.logrocket.com/testing-typescript-apps-using-jest/ (@ibywaks)
- https://khalilstemmler.com/blogs/typescript/eslint-for-typescript/ (@stemmlerjs)
- https://khalilstemmler.com/blogs/tooling/prettier/ (@stemmlerjs)

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