Working with ISO 8601 in date-fns

How date-fns parses and formats ISO 8601 strings, what each conversion changes, common time zone pitfalls, and when a localized display is the better choice.

ISO 8601 is the international standard for writing dates and times as text, such as 2026-03-05 or 2026-03-05T14:30:00Z. The date-fns JavaScript library has dedicated functions for reading and writing this notation. This review explains what those conversions change, where they can lose or shift meaning, and when a localized, human-readable date is the better choice. It is based on documented library behavior and general principles. No test results or measurements were supplied, and gaps are noted where they matter.

Is ISO 8601 output from date-fns right for your use?

For data exchange, it usually is. Use it for storage, APIs, logs, file names and anything another program must read back. The main benefit is an unambiguous, locale-independent string. The month and day order cannot be misread, and a time with an offset identifies one exact instant.

The decisive tradeoff is time zone handling. formatISO writes the time in the local zone of the machine running the code, with that zone's offset. Date.prototype.toISOString always writes UTC. parseISO treats strings without an offset as local time. If you mix these without a clear rule, the same moment can be stored as different strings, or a date can shift by a day.

Plain or localized text is preferable when the reader is a person rather than a program. Examples include interface labels, emails, printed documents and spoken output. In those places, a phrase like March 5, 2026 is easier to read than 2026-03-05T09:30:00-05:00.

What the conversion actually changes

A JavaScript Date stores a single instant as a number of milliseconds since the Unix epoch. It does not store a format, a locale or a time zone. Formatting to ISO 8601 creates a new text string that represents that instant. Parsing turns a string back into a Date. Neither step changes the meaning of a valid instant, but each step can change what is visible in the text: which zone the clock time is shown in, whether milliseconds appear, and whether separators are used.

In this context, "transformation" means converting between a date value and its text form. Visual effects such as reversed, mirrored or font-styled text do not apply here. They would break ISO strings, as explained in the section on copying and sharing.

Function | Direction | What it produces or expects
parseISO | string to Date | Reads ISO 8601 text; strings without an offset are treated as local time; unreadable input returns an Invalid Date
formatISO | Date to string | Local clock time plus the local offset, or Z when the offset is zero; no milliseconds
formatISO with representation: 'date' or 'time' | Date to string | Only the date part or only the time part
formatISO with format: 'basic' | Date to string | The same values without hyphens and colons
formatISO9075 | Date to string | The SQL-style form with a space between date and time
formatRFC3339 | Date to string | The RFC 3339 profile of ISO 8601, with optional fraction digits
Date.prototype.toISOString (native) | Date to string | Always UTC, always with milliseconds and a trailing Z
import { parseISO, formatISO } from 'date-fns';

const d = parseISO('2026-03-05T14:30:00Z');

formatISO(d);
// Local time with offset. In an environment at UTC-5:
// '2026-03-05T09:30:00-05:00'

formatISO(d, { representation: 'date' });
// '2026-03-05' (the local date)

formatISO(d, { format: 'basic' });
// '20260305T093000-0500' in the same UTC-5 environment

d.toISOString();
// '2026-03-05T14:30:00.000Z' everywhere

The outputs in the example depend on the zone of the machine running the code. All of the strings describe the same instant, but they are not equal as text. If you compare or sort stored dates as strings, pick a single convention for every record. Writing everything in UTC with toISOString is a common choice.

Parsing: the date-only pitfall

A frequent source of off-by-one-day bugs is a string that has a date but no time. parseISO reads it as local midnight. The native Date constructor follows the ECMAScript rule and reads date-only ISO strings as UTC midnight. In time zones west of UTC, which includes all of the US, the native result shows as the previous evening when displayed locally.

import { parseISO, isValid } from 'date-fns';

parseISO('2026-03-05');
// Local midnight on March 5

new Date('2026-03-05');
// UTC midnight; displayed locally in a US zone it is March 4

isValid(parseISO('03/05/2026'));
// false: not ISO 8601, so the result is an Invalid Date

parseISO does not throw on bad input. It returns an Invalid Date, so check the result with isValid before you use it. For non-ISO input such as 03/05/2026, use parse with an explicit pattern instead. That string is ambiguous between US and European conventions, and no parser can resolve that on its own.

Custom patterns with format

When formatISO's options are not enough, format accepts Unicode-style tokens. The tokens are case-sensitive, and a few lookalikes mean something different:

  • yyyy is the calendar year. YYYY is the week-numbering year, which differs from the calendar year near New Year. By default, date-fns throws an error when YYYY is used, unless you enable it explicitly.
  • dd is the day of the month. DD is the day of the year, and it is also guarded by default.
  • MM is the month and mm is minutes. HH is the 24-hour clock and hh is the 12-hour clock.
  • XXX writes Z for a zero offset and ±hh:mm otherwise. xxx always writes ±hh:mm, including +00:00.
  • Literal text such as the T separator must be wrapped in single quotes.
import { format } from 'date-fns';

format(d, "yyyy-MM-dd'T'HH:mm:ssXXX");
// Equivalent in shape to formatISO(d)

Time zones beyond the local machine

The core formatting functions work in the runtime's local zone. That means a server and a browser can produce different strings from the same Date. To format or parse in a specific named zone, such as a user's zone on a server, you need extra support. Older setups commonly used the separate date-fns-tz package. Version 4 added first-class time zone support through a companion package. The details differ between major versions, so check the documentation for the version you have installed. If you only need a stable, zone-independent value, write in UTC instead.

Will the result stay readable and usable after copying or sharing?

An ISO 8601 string from date-fns contains only ASCII digits, hyphens, colons, the letter T, a sign and possibly Z. That makes it robust for copying into plain-text fields, code, configuration files and query strings. Problems usually come from what happens to the string after it is pasted:

  • Spreadsheet applications may automatically convert pasted date-like text into their own date values and reformat or re-zone it. Behavior varies by product and settings. No tests were supplied for any specific application, so check yours, or import the column as text.
  • Styled or substituted digits break parsing. Fullwidth digits and "bold" or "script" Unicode numerals may look like numbers, but parseISO matches only ASCII 0-9 and will return an Invalid Date. Apply decorative text styling only to display copies, never to stored values.
  • In right-to-left text, neighboring characters can affect how a timestamp is displayed, even though the stored characters stay the same. Isolating the date, for example with an element set to left-to-right direction, keeps its visual order predictable. Test this in each target environment rather than assuming one rendering applies everywhere.
  • Search and editing work well on the raw string. Lexicographic sorting matches chronological order only when every value uses the same format, precision and offset.

For accessibility, the documented approach in HTML is to show a readable, localized date to people and keep the ISO value in the datetime attribute of a time element. Programs read the attribute, and people and assistive technology get the visible text. How individual screen readers announce a raw string like 2026-03-05T09:30:00-05:00 was not tested for this review. Don't assume it will be spoken clearly. If people will hear or read the date, give them a plain-language equivalent.

When to use a localized format instead

  • Dates shown in a user interface, notifications or documents: format with a locale, or use Intl.DateTimeFormat, and keep the ISO string behind the scenes.
  • Calendar dates without a meaningful time, such as birthdays or deadlines: store the date-only string (yyyy-MM-dd) and avoid turning it into an instant, so it cannot shift across zones.
  • Content that will be read aloud or reused by non-technical readers: use a written-out month to avoid ambiguity and reading difficulty.

Evidence gaps

This review relies on documented date-fns and JavaScript behavior. No version-specific test results, benchmarks or destination-specific copy-and-paste tests were supplied. Before relying on a particular spreadsheet, messaging app, database driver or screen reader, test it with your own data. Also confirm option names and default behavior against the documentation for your installed major version.