Format Salesforce dates and times with time zones

How Salesforce stores and displays date/time values, how to format them with a specific time zone in Apex, formulas, SOQL and Lightning components, and when raw UTC text is the safer choice.

Formatting a Salesforce date/time for a particular time zone is a presentation step. The underlying value does not change. Most problems come from confusing the two: a value that looks wrong in a report, email or export usually has the right stored instant shown in an unexpected zone or text pattern. This review covers what formatting changes, which formatting route fits which job, and when an unformatted UTC string is the better output.

Evidence note: no product-specific test results, release notes or measurements were supplied for this article. The behavior described below is drawn from Salesforce's generally documented platform conventions. Behavior can differ by release, org settings and API version, so verify it in a sandbox before relying on it in production.

Is formatting with a time zone the right choice for your use?

Format with a named time zone when people will read the value and need it in a zone other than their own. Examples include a customer-facing email that states an appointment in the customer's local time, or a document generated for a team in a fixed region. The benefit is that the text is unambiguous to the human reader.

The main tradeoff is that a formatted string is no longer a date/time. Once you turn a value into text such as a month name, a 12-hour clock and a zone abbreviation, it stops sorting chronologically. It also can't be compared or filtered as a date. Another system can parse it back only if it knows the exact pattern and locale.

Plain, unformatted output is preferable for storage, integrations, logs, CSV exports meant for re-import, and anything another system will parse. In those cases, emit ISO 8601 in UTC, or ISO 8601 with an explicit numeric offset, and leave localization to the receiving side.

What formatting actually changes

A Salesforce Date/Time field stores a single instant, held in UTC (Salesforce often labels it GMT). The platform has no per-record time zone. When a user views the record, list view or report, Salesforce renders that instant in the viewing user's personal time zone, using the pattern set by their locale. Two users in different zones see different text for the same stored value, and both are correct.

A Date field stores only a calendar day, with no time and no time zone. A Time field stores a time of day without a date. Converting between these types is where days most often shift unexpectedly, because Salesforce has to pick a zone in which to cut the instant into a calendar day.

The word "format" is used for three different things, and it helps to keep them apart:

  • Locale format: the user setting that controls display order and separators, such as month/day/year versus day/month/year.
  • Time zone: the user setting, or an explicit argument in code, that controls which wall-clock time the instant is shown as.
  • Format pattern: an explicit text template in code, such as yyyy-MM-dd HH:mm z, that builds a specific string.

Changing any of these changes only the rendered text. None of them alters the stored UTC instant unless you write the resulting string, or a shifted value, back into a field.

Formatting routes and how each handles time zones

Route | Default zone for output | Can you choose a named zone? | Main caveat
Standard record and report display | Viewing user's time zone | No, it follows user settings | The same record reads differently for different users
Apex Datetime.format() | Running user's time zone | Yes, via the overload that takes a time zone ID | Output depends on the user context the code runs as
Apex Datetime.formatGMT() | UTC | Not needed; always UTC | Good for machine output, not for reader-facing text
Formula TEXT() on a date/time | UTC, in an ISO-like form ending in Z | No built-in named-zone conversion | Manual offsets do not follow daylight saving time
SOQL literals and filters | UTC, unless an offset is given | Offset in the literal; convertTimezone() for date functions | convertTimezone() converts to the user's zone only
Lightning lightning-formatted-date-time | Viewing user's time zone | Yes, via the time-zone attribute | Display-only; the bound value stays unchanged

Apex

In Apex, the Datetime class supports both locale-based and pattern-based output. Called with no arguments, format() uses the running user's locale and time zone. The overload that takes a pattern and a time zone ID renders the instant in the zone you name. formatGMT() renders in UTC. Patterns follow Java SimpleDateFormat conventions. Inside a pattern, z outputs a zone abbreviation, Z outputs a numeric offset, and literal letters are wrapped in single quotes.

Datetime dt = Datetime.now();

// Running user's locale and time zone
String forUser = dt.format();

// Explicit pattern, explicit IANA time zone ID
String forNewYork = dt.format('yyyy-MM-dd HH:mm z', 'America/New_York');

// Machine-readable ISO 8601 in UTC
String isoUtc = dt.formatGMT('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'');

Use full region-based time zone IDs such as America/New_York rather than abbreviations. A region ID carries daylight saving rules, while abbreviations are ambiguous across regions.

When you extract a calendar day in Apex, date() uses the user's local zone and dateGmt() uses UTC. For instants near midnight, these can return different days.

Formula fields and Flow formulas

Formulas have no function that converts a date/time to a named time zone. TEXT() applied to a date/time returns a UTC representation, not the viewer's local time. DATEVALUE() applied to a date/time is likewise evaluated in UTC, so a late-evening record in a western zone can produce the next day's date.

A common workaround is to subtract a fraction of a day for the offset, as in the example below. This shifts the instant by a fixed amount and does not adjust for daylight saving changes. Treat it as approximate unless your target zone has no daylight saving time, or you add explicit date-range logic.

TEXT(CreatedDate)            /* UTC text, ends in Z */
DATEVALUE(CreatedDate)       /* calendar day evaluated in UTC */
CreatedDate - (5/24)         /* fixed 5-hour shift; ignores daylight saving */

SOQL

Date/time literals in SOQL use ISO 8601 and are interpreted as UTC when they end in Z. You can also give an explicit numeric offset. Date functions such as HOUR_IN_DAY or DAY_ONLY work in UTC unless you wrap the field in convertTimezone(). That function converts to the querying user's time zone; it does not accept an arbitrary zone.

SELECT Id, CreatedDate FROM Case WHERE CreatedDate >= 2026-01-01T00:00:00Z

SELECT HOUR_IN_DAY(convertTimezone(CreatedDate)), COUNT(Id)
FROM Case
GROUP BY HOUR_IN_DAY(convertTimezone(CreatedDate))

Lightning Web Components

The lightning-formatted-date-time base component renders a value in the viewer's zone by default. Its time-zone attribute lets you name a different zone, and time-zone-name adds a short or long zone label to the output. This affects display only, which makes it a good fit when a page must show a fixed regional time without changing data.

<lightning-formatted-date-time
    value={createdDate}
    year="numeric" month="short" day="2-digit"
    hour="2-digit" minute="2-digit"
    time-zone="America/Chicago"
    time-zone-name="short">
</lightning-formatted-date-time>

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

A formatted string copies and pastes as ordinary text, so its characters survive. Its meaning may not. A pasted value like "03/04 2:00 PM CST" depends on the reader knowing the day/month order. It also depends on them knowing which zone CST refers to, since the abbreviation is used for more than one region. If the text loses its zone label along the way, the time becomes unrecoverable.

  • For people: include the zone explicitly, preferably as a region name or numeric offset. Spell out the month or use a year-first order to avoid day/month confusion.
  • For systems: send ISO 8601 with Z or a numeric offset. Avoid locale patterns, 12-hour clocks and abbreviations.
  • For spreadsheets: text in a locale pattern may be re-interpreted by the spreadsheet's own locale settings on open. ISO 8601 with an explicit offset is the least ambiguous. Whether a given spreadsheet treats it as a date or as text depends on that application, so test it.
  • For data loading: data loading tools commonly apply a configured time zone when they read date/time values that carry no offset. Check that setting before importing local-time strings, or include the offset in the data.

On accessibility: no assistive-technology testing was available for this review. Formatted output that writes out the month and uses a clear zone name is generally easier to read aloud than a dense numeric ISO string. However, the way a particular screen reader announces either form has not been verified here. Where a value is reader-facing, a reasonable practice is to show a human-readable local form and keep the machine-readable ISO value available separately, for example in an export column or an underlying data attribute. Test with the screen readers your audience actually uses.

Formatted text also limits editing and search. A string field holding a formatted date cannot be filtered with date operators or sorted chronologically in reports. Searching for it also requires matching the exact rendered pattern. Keep the original Date/Time field as the source of truth, and generate formatted text only where a reader or document needs it.

Known gaps to check in your own org

  • Daylight saving behavior of any formula that applies a manual offset, tested on dates on both sides of each transition.
  • Which user context your Apex, Flow or scheduled job runs as, since that determines the default zone.
  • The time zone setting in whatever import or integration tool you use.
  • How the destination of a copied or exported value (email client, spreadsheet, external API) interprets the pattern you send.
  • Screen reader announcement of your chosen output format, if the value is reader-facing.