---
title: "How do I format a date in JavaScript?"
description: "Format dates in JavaScript with toLocaleDateString and Intl.DateTimeFormat instead of a library. Covers locales, time zones, custom parts and ISO strings for machines."
url: https://www.danny.engineering/answer/javascript/how-do-i-format-a-date-in-javascript
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T18:57:00.000Z
tags: ["Javascript"]
---

# How do I format a date in JavaScript?

## The short answer


Use the built-in `Intl.DateTimeFormat`, or its shortcut `toLocaleDateString`. Pass a locale and an options object describing what you want to show, and the browser handles month names, order and separators for you. For dates that machines read, use `toISOString`.


```javascript
const date = new Date('2026-11-27T14:30:00Z');

date.toLocaleDateString('en-GB', { dateStyle: 'long' });
// "27 November 2026"

new Intl.DateTimeFormat('en-GB', {
  weekday: 'short',
  day: 'numeric',
  month: 'short',
  year: 'numeric',
}).format(date);
// "Fri 27 Nov 2026"
```


## Why it happens


JavaScript's `Date` has no `format` method that takes a pattern like `DD/MM/YYYY`. Older code filled the gap with libraries such as Moment.js, or by gluing together `getDate()`, `getMonth()` and `getFullYear()` by hand. Both approaches tend to go wrong: the month is zero-based, hand-built strings ignore the reader's locale, and big libraries add weight.


The `Intl` API, built into every modern browser and Node, solves this properly. You describe the parts you want, and it produces the right output for the locale, including translated month names and the correct order of day, month and year.


## How to fix it


### Use dateStyle and timeStyle for common formats


`dateStyle` and `timeStyle` accept `"full"`, `"long"`, `"medium"` and `"short"`. They cover most interface needs in one option.


```javascript
const date = new Date('2026-11-27T14:30:00Z');

date.toLocaleString('en-GB', {
  dateStyle: 'medium',
  timeStyle: 'short',
  timeZone: 'Europe/London',
});
// "27 Nov 2026, 14:30"

date.toLocaleDateString('en-US', { dateStyle: 'short' });
// "11/27/26"
```


You cannot mix `dateStyle` or `timeStyle` with individual options like `month` or `weekday`. Doing so throws a `TypeError`.


### Pick individual parts for custom formats


For anything else, list the parts you need. Each one takes values such as `"numeric"`, `"2-digit"`, `"short"` or `"long"`.


```javascript
const formatter = new Intl.DateTimeFormat('en-GB', {
  day: '2-digit',
  month: '2-digit',
  year: 'numeric',
});

formatter.format(new Date('2026-03-05'));
// "05/03/2026"
```


Create the formatter once and reuse it when formatting many dates, for example in a table. Building a new one each time is slower.


### Set the time zone explicitly


By default, dates are shown in the time zone of the device. On a server, that is often UTC. If the output must match a particular place, pass `timeZone` with an IANA name.


```javascript
const options = { dateStyle: 'full', timeStyle: 'short' };

new Intl.DateTimeFormat('en-GB', { ...options, timeZone: 'Asia/Tokyo' })
  .format(new Date('2026-11-27T23:30:00Z'));
// "Saturday 28 November 2026 at 08:30"
```


This matters for server-rendered pages, where the server and the browser can format the same date differently.


### Use formatToParts for full control


If you need to style parts separately or build an exact string, `formatToParts` returns an array of typed pieces.


```javascript
const parts = new Intl.DateTimeFormat('en-GB', {
  day: 'numeric',
  month: 'long',
}).formatToParts(new Date('2026-11-27'));

const day = parts.find((part) => part.type === 'day').value;     // "27"
const month = parts.find((part) => part.type === 'month').value; // "November"
```


### Use ISO strings for data


For APIs, databases, file names and logs, use a fixed format that does not depend on locale.


```javascript
new Date().toISOString();                  // "2026-11-27T14:30:00.000Z"
new Date().toISOString().slice(0, 10);     // "2026-11-27"
```


## Common pitfalls

- Forgetting that `getMonth()` is zero-based. January is `0`, so hand-built strings are often a month out.
- Parsing `new Date('2026-11-27')`. A date-only ISO string is treated as UTC midnight, which can show as the previous day in time zones west of UTC.
- Leaving out the locale. `toLocaleDateString()` with no arguments uses the device's locale, so tests and screenshots differ between machines.
- Relying on the exact output in tests. Browsers occasionally change spacing or punctuation between versions, so compare parts or ISO strings instead.
- Formatting relative times by hand. Use `Intl.RelativeTimeFormat` for "3 days ago". For date arithmetic, see the newer Temporal API.

## Related reading

- [MDN: Intl.DateTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat)
- [MDN: Date.prototype.toLocaleDateString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
