# prefer-temporal

Rule `unicorn/prefer-temporal`. Prefer `Temporal` over `Date`.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #2038 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/prefer-temporal` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/prefer-temporal.md) |

## Code examples

### Incorrect: the rule reports this

```js
const now = new Date();
```

```js
const date = new Date(1_724_198_400_000);
```

```js
const date = new Date('2024-08-16');
```

### Correct: the rule accepts this

```js
const now = Temporal.Now.instant();
```

```js
const date = Temporal.Instant.fromEpochMilliseconds(1_724_198_400_000);
```

```js
const date = Temporal.PlainDate.from('2024-08-16');
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/prefer-temporal": "error",
    },
  },
];
```

## Related rules

- [unicorn/prefer-short-arrow-method](https://lintradar.dev/rules/unicorn/prefer-short-arrow-method.md): Prefer arrow function properties over methods with a single return.
- [unicorn/prefer-uint8array-base64](https://lintradar.dev/rules/unicorn/prefer-uint8array-base64.md): Prefer `Uint8Array#toBase64()` and `Uint8Array.fromBase64()` over legacy base64 conversions and manual postprocessing.
- [unicorn/prefer-regexp-escape](https://lintradar.dev/rules/unicorn/prefer-regexp-escape.md): Prefer `RegExp.escape()` for escaping strings to use in regular expressions.
- [unicorn/prefer-uint8array-hex](https://lintradar.dev/rules/unicorn/prefer-uint8array-hex.md): Prefer `Uint8Array#toHex()` and `Uint8Array.fromHex()` over manual and Buffer hex conversions.
- [unicorn/require-frontmatter-fields](https://lintradar.dev/rules/unicorn/require-frontmatter-fields.md): Require configured YAML frontmatter fields.
- [unicorn/prefer-json-import](https://lintradar.dev/rules/unicorn/prefer-json-import.md): Prefer JSON imports over reading and parsing JSON files.

---

Web page: https://lintradar.dev/rules/unicorn/prefer-temporal. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
