toolqik

208 · JavaScript

JavaScript Date Formatter

Format dates in JavaScript: every built-in method, Intl.DateTimeFormat options and format patterns.

Runs in your browser

Format pattern

Result

  
Plain JavaScript, no library

  

Intl.DateTimeFormat

Result

  
Code

  

Built-in methods

About this tool

Formatting a date in JavaScript usually means one of three things, and this page covers all three for any date, locale and time zone you choose:

  1. A fixed pattern like 2025-03-14 09:30 for logs, file names or APIs. Type a pattern with tokens like YYYY, MM and HH and get the result plus a small plain-JavaScript function that produces it, no library needed.
  2. A localised format for people to read, with Intl.DateTimeFormat or toLocaleString. Pick options and see the output and the exact code.
  3. A built-in method such as toISOString(). The table shows what each one returns for your date.

Pattern tokens

YYYY year, YY two-digit year, MMMM month name, MMM short month, MM 01–12, M 1–12, DD 01–31, D 1–31, dddd weekday name, ddd short weekday, HH 00–23, hh 01–12, h 1–12, mm minutes, ss seconds, SSS milliseconds, A AM/PM, Z offset like +05:30. Text in [brackets] is kept as is. These match Day.js and Moment, so patterns carry over.

Pitfalls

  • new Date('2025-03-14') is UTC midnight, but new Date('2025-03-14T00:00') is local midnight.
  • getMonth() is zero-based: January is 0.
  • toISOString() is always in UTC, so it can show a different day from the local date.
  • Create one Intl.DateTimeFormat and reuse it when formatting many dates; it’s much faster than calling toLocaleString each time.

FAQ

How do I format a date as YYYY-MM-DD in JavaScript?

Use the pattern YYYY-MM-DD above to get a small function, or for UTC dates date.toISOString().slice(0, 10). The en-CA locale also formats dates as YYYY-MM-DD.

What is the difference between toLocaleString and Intl.DateTimeFormat?

They produce the same output. Intl.DateTimeFormat creates a reusable formatter, which is faster for many dates and offers formatToParts.

How do I show a date in another time zone?

Pass timeZone, such as { timeZone: "America/New_York" }, to Intl.DateTimeFormat or toLocaleString. The Date itself has no zone; only formatting does.

Do I need Moment.js or date-fns?

For formatting, usually not: Intl covers localised output and a few lines handle fixed patterns. Libraries still help with complex date arithmetic and parsing.

Why is my date off by one day?

Usually UTC versus local time: a date-only ISO string is parsed as UTC, and toISOString prints UTC. Format in local time or pass the right timeZone.

esc
↑↓ navigate↵ open