SKU // 61

JavaScript Date Formats

Date formatting runs in two directions. Input: which text strings JavaScript can reliably turn into a Date. Output: how to turn a Date back into text that people (or other programs) can read.

// Input: The Safe Format Is ISO

ISO 8601 (year-month-day, largest unit first) is the only string format every browser is guaranteed to read the same way:

String Means
"2026-10-02"Midnight, UTC (see the trap in JS Dates)
"2026-10-02T14:30"2:30 PM, local time
"2026-10-02T14:30:00Z"2:30 PM UTC (the Z means UTC)
"2026-10-02T14:30:00-04:00"2:30 PM at 4 hours behind UTC
Avoid
Strings like "10/02/2026" or "Oct 2 2026" usually work in browsers, but they are not part of the standard. "02/10/2026" means October 2 to an American and February 10 to most of the world. Stick to ISO for anything your code creates.

Shorter ISO strings

ISO dates can leave off the day, or the month and day. The missing parts become the 1st, at midnight UTC, so in the Americas the result lands on the evening before:

console.log(new Date("2015-03").toString());    // March 1, UTC
console.log(new Date("2015").toString());       // January 1, UTC
Sat Feb 28 2015 19:00:00 GMT-0500 (Eastern Standard Time) Wed Dec 31 2014 19:00:00 GMT-0500 (Eastern Standard Time)

Date and time are separated by a capital T, and a capital Z means UTC. Leaving out the T or Z in a date-time string can give different results in different browsers.

// Input: Other Formats

Browsers also accept two other kinds of string. They usually work, but they are not part of the standard, so behavior can vary:

TypeExample
ISO date (the standard)"2015-03-25"
Short date"03/25/2015" (MM/DD/YYYY)
Long date"Mar 25 2015", "25 Mar 2015", "January 25 2015"

Long dates are forgiving: the month and day can be in either order, the month can be full or abbreviated, commas are ignored, and case does not matter. new Date("JANUARY, 25, 2015") works.

Watch out: one missing zero changes the time zone
"2015-03-25" is ISO, so it means midnight UTC. But "2015-3-25" (no leading zero) is not valid ISO, so Chrome falls back to guessing and reads it as midnight local time: a different moment, possibly a different day. Other formats are worse: "2015/03/25" behaves differently between browsers, and "25-03-2015" gives Invalid Date in Chrome. Pad your numbers and stick to ISO.

// Date.parse()

Date.parse() reads a date string and returns its timestamp in milliseconds, instead of a Date object. You can then pass that number to new Date():

let msec = Date.parse("March 21, 2012");
console.log(msec);
console.log(new Date(msec).toDateString());
1332302400000 Wed Mar 21 2012

(The exact number depends on your time zone.) It follows the same rules as new Date(string), including returning NaN for a string it cannot read.

// Output: Built-in String Methods

const d = new Date(2026, 9, 2, 14, 30);

d.toString()       // "Fri Oct 02 2026 14:30:00 GMT-0400 (Eastern Daylight Time)"
d.toDateString()   // "Fri Oct 02 2026"
d.toTimeString()   // "14:30:00 GMT-0400 (Eastern Daylight Time)"
d.toISOString()    // "2026-10-02T18:30:00.000Z"
d.toUTCString()    // "Fri, 02 Oct 2026 18:30:00 GMT"
Fri Oct 02 2026 14:30:00 GMT-0400 (Eastern Daylight Time) Fri Oct 02 2026 14:30:00 GMT-0400 (Eastern Daylight Time) 2026-10-02T18:30:00.000Z Fri, 02 Oct 2026 18:30:00 GMT

Notice toISOString and toUTCString show 18:30. They always convert to UTC, which is four hours ahead of Eastern Daylight Time.

Tip
Use toISOString() when saving a date or sending it to a server. It is exact, sorts correctly as plain text, and new Date() can read it straight back in.

// Output for People: toLocaleDateString

The toLocale... methods format a date the way people in a given region expect. Pass a locale code:

d.toLocaleDateString("en-US")   // "10/2/2026"   (United States)
d.toLocaleDateString("en-GB")   // "02/10/2026"  (United Kingdom)
d.toLocaleDateString("de-DE")   // "2.10.2026"   (Germany)
d.toLocaleTimeString("en-US")   // "2:30:00 PM"

// Choosing the Pieces with Options

A second argument controls exactly which parts appear and how:

d.toLocaleDateString("en-US", {
  weekday: "long", year: "numeric", month: "long", day: "numeric"
});
// "Friday, October 2, 2026"

d.toLocaleDateString("en-US", { month: "short", day: "numeric" });
// "Oct 2"

d.toLocaleTimeString("en-US", { hour: "numeric", minute: "2-digit" });
// "2:30 PM"
Friday, October 2, 2026 Oct 2 2:30 PM
Option Values
weekday"long" (Friday), "short" (Fri), "narrow" (F)
year"numeric" (2026), "2-digit" (26)
month"long", "short", "narrow", "numeric", "2-digit"
day / hour / minute"numeric", "2-digit"
timeZone"America/New_York", "Europe/London", "UTC"...

// Showing Another Time Zone

d.toLocaleTimeString("en-US", { timeZone: "Europe/London", hour: "numeric", minute: "2-digit" });
// "7:30 PM"  (the same moment, on a clock in London)

// Building a Custom Format

For an exact fixed pattern like YYYY-MM-DD in local time, build it from the parts (covered fully in Date Get):

function ymd(date) {
  const y = date.getFullYear();
  const m = String(date.getMonth() + 1).padStart(2, "0");
  const day = String(date.getDate()).padStart(2, "0");
  return `${y}-${m}-${day}`;
}

console.log(ymd(d));
2026-10-02

// Which Format When?

Saving / sendingtoISOString()
Showing to peopletoLocaleDateString() with options
A fixed custom patternbuild it from getFullYear / getMonth / getDate

// Quick Check

You are saving a date to send to a server. Which format should you use?

  1. toString()
  2. toLocaleDateString("en-US")
  3. toISOString()
  4. "10/02/2026"
Show answer
C. ISO is exact, includes the time zone (UTC), sorts correctly as text, and new Date() reads it straight back. The locale format is for people, and "10/02/2026" means different dates in different countries.

Why is "02/10/2026" a risky date string?

  1. It is too long
  2. Americans read it as February 10; most of the world reads October 2
  3. It is always Invalid Date
  4. Slashes are not allowed in strings
Show answer
B. Short dates are ambiguous and not part of the standard. ISO ("2026-10-02") always puts the largest unit first.

What does this log?

const d = new Date(2026, 9, 2);
console.log(d.toLocaleDateString("en-US", { month: "long", day: "numeric" }));
Show answer
October 2. The options ask for only the month (as a full name) and the day, so the year and weekday are left out.

// Try It

  1. Click Open Playground. Format today's date in "en-US", "en-GB", and "ja-JP"
  2. Produce "Friday, October 2" (no year) using options
  3. Show what time it is right now in Tokyo using timeZone: "Asia/Tokyo"
  4. Save a date with toISOString(), then read it back with new Date() and confirm the times match
// Video Walkthroughs
Last updated: Oct 10, 2026, 1:41 AM ET