Formatting Date Strings with date-fns: ISO Input, Output and Time Zones
A practical review of formatting ISO date strings with date-fns: what format changes, how to drop or keep the time zone offset, and when the result stays readable.
date-fns is a JavaScript library of small functions for working with dates. Its format function turns a date into a string from a pattern you supply. That makes it a common way to reshape an ISO timestamp from an API into something a person can read, or into a different machine format. This review covers what that transformation does to the data, where it can quietly change meaning, and when you are better off leaving the original string alone.
Is date-fns formatting the right fit?
For display, date-fns formatting is a reasonable choice. You get explicit, readable patterns, locale-aware output, and a short path from an ISO string to a human-friendly date. The decisive tradeoff is time zones. By default, date-fns formats in the time zone of the environment running the code. The same input can therefore produce different text on a server and in a browser, or for users in different regions. If your patterns drop the offset, that difference disappears from the output, and nobody reading it can tell which zone it reflects.
- Keep the original ISO string, or use a native method, in these cases:
- Storing or exchanging timestamps between systems. The original ISO string with its offset or Z suffix is the unambiguous record, so format only at the point of display.
- You only need a UTC ISO timestamp. The built-in toISOString method on a Date already produces one, with no library involved.
- You only need locale-appropriate display and already rely on the built-in Intl.DateTimeFormat API. It may cover the need without an added dependency.
What format actually changes
In this context, 'format' means serializing a date into text. It has nothing to do with fonts or visual styling. A JavaScript Date holds a single instant in time. The format function reads that instant, converts it to the local calendar date and clock time of the runtime, and builds a new string from your pattern. The original Date and the original ISO string are not modified. What changes is the representation you hand onward. Information the pattern leaves out is absent from that new string: seconds, the year, the offset, and so on.
When your input is an ISO string, convert it to a Date first with parseISO. Whether format accepts a raw string directly has varied between major versions. Even where it does, explicit parsing makes the behavior clear. parseISO honors an offset or Z suffix in the string. When the string has none, parseISO interprets it as local time.
import { parseISO, format } from 'date-fns';
const d = parseISO('2026-03-04T15:30:00Z');
format(d, 'yyyy-MM-dd HH:mm');
// '2026-03-04 15:30' when the runtime time zone is UTC
// '2026-03-04 10:30' when the runtime time zone is America/New_York
Pattern tokens are case-sensitive, and several look alike. date-fns follows Unicode date-pattern conventions, with some differences. Literal text, such as the T in an ISO-style timestamp, must be wrapped in single quotes. Otherwise letters are read as tokens. date-fns throws an error for the YYYY and DD tokens unless you opt in through the useAdditionalWeekYearTokens or useAdditionalDayOfYearTokens options. This catches a frequent mistake. An invalid date, such as the result of parsing a malformed string, makes format throw a RangeError instead of returning text.
| Token | Meaning | Common confusion |
| yyyy | Calendar year | YYYY is the week-numbering year, which can differ near January 1 |
| MM | Month, zero-padded | mm is minutes |
| dd | Day of month, zero-padded | DD is day of the year |
| HH | Hour, 0–23 | hh is the 12-hour clock and needs a or aaa for AM/PM |
| xxx / XXX | Offset such as -05:00; XXX prints Z for zero offset | Omitting these drops the time zone from the output |
| 'T' | Literal T character | An unquoted T is not treated as a separator |
Getting ISO output back
To turn a date back into an ISO string, date-fns provides formatISO. It writes the local time together with its offset. Its representation option limits the output to just the date or just the time. Related functions cover other standards: formatISO9075, formatRFC3339 and formatRFC7231. If you specifically want UTC with a Z suffix, the native toISOString method is the direct route.
import { parseISO, formatISO } from 'date-fns';
const d = parseISO('2026-03-04T15:30:00Z');
// In a runtime set to America/New_York:
formatISO(d); // '2026-03-04T10:30:00-05:00'
formatISO(d, { representation: 'date' }); // '2026-03-04'
d.toISOString(); // '2026-03-04T15:30:00.000Z'
Formatting without a time zone
Leaving the offset out of the output is easy. Write a pattern without offset tokens, for example yyyy-MM-dd'T'HH:mm:ss. The result is the local wall-clock time of the runtime with no zone marker. This works well for values that really have no zone, such as a birthday or a due date. For real instants, it is risky. Once the string leaves the system, a reader or another program will assume some zone, and that assumption may be wrong.
Date-only strings need particular care. Under the JavaScript language rules, the native Date constructor treats a date-only ISO string as UTC midnight. In a time zone behind UTC, that instant falls on the previous local day. parseISO treats the same string as local midnight, so it formats back to the date you started with.
import { parseISO, format } from 'date-fns';
// In a runtime set to America/New_York:
format(new Date('2026-03-04'), 'yyyy-MM-dd'); // '2026-03-03'
format(parseISO('2026-03-04'), 'yyyy-MM-dd'); // '2026-03-04'
Sometimes you need output in a particular zone, not the runtime's zone. A typical example is showing every user a store's local opening time. date-fns does not handle this on its own in older versions. The companion package date-fns-tz offers formatInTimeZone for that purpose. Version 4 of date-fns added time zone support through the @date-fns/tz package and its TZDate class. Check which major version your project uses before you choose an approach.
Will the result stay readable and usable after copying or sharing?
The output of format is ordinary text, not styled characters or a visual effect. It copies, pastes, searches and edits like any other string, and its reading order does not change. The risks come from meaning, not from rendering. A formatted date can read cleanly and still be ambiguous or wrong once it leaves the context where it was created.
- Numeric day and month order: 03/04/2026 means March 4 to most US readers and 4 March in many other regions. Use yyyy-MM-dd or a spelled-out month when the audience is mixed.
- Missing offsets: a shared timestamp without a zone may be read in the recipient's zone, which shifts the time.
- Sorting and search: zero-padded yyyy-MM-dd strings sort correctly as plain text. Locale-formatted strings generally do not.
- Locale output: localized patterns such as PPP depend on the locale you pass. For example, format(d, 'PPP', { locale: enUS }) yields 'March 4th, 2026'. Text produced for one locale may confuse readers using another.
For accessibility, a spelled-out date such as March 4th, 2026 is generally clearer to listen to than a string of digits and slashes. No testing with specific screen readers was available for this review, so how a given assistive technology announces a particular numeric format remains unverified. On web pages, a practical pattern is to show the localized text and keep a machine-readable ISO value alongside it, for instance in the datetime attribute of an HTML time element. People and software then each get a version they can use.
Gaps in this review
The behavior described here comes from the documented design of date-fns and general JavaScript date rules. It does not come from benchmarks or hands-on tests. Example outputs assume the stated runtime time zone. No measurements of bundle size or performance, and no assistive technology results, were available. Version-specific details, especially string input handling and time zone support, should be confirmed against the documentation for the release you install.