Skip to main content

Description

Converts a date/time instant to represent the wall clock time in a given timezone offset. The returned Date represents the same instant but shifted so UTC fields reflect local time.

Syntax

Parameters

Returns

Type: Date A Date object adjusted to show local time in the given timezone. Returns null if input is invalid. Returns original date if timezone format is invalid.

Examples

Example 1: Convert UTC to Eastern Time

Output:
(UTC fields now show 09:00 which is the local time in -05:00)

Example 2: Convert to Multiple Time Zones

Example 3: Display User Events in Local Time

Example 4: Adjust for Daylight Saving Time Context

Notes

  • Returns null for invalid date inputs
  • Invalid timezone format returns the original date unchanged
  • Timezone format accepts +HH:MM, -HH:MM, +HHMM, or -HHMM
  • Does not handle DST transitions automatically
  • The returned Date’s UTC methods will show the local time
  • Useful for displaying times in user’s local timezone

See Also

Frequently Asked Questions

It converts a date/time value to a different timezone by applying an offset, returning the adjusted date/time.
The offset is specified as a numeric value representing hours (e.g., -5 for EST, +9 for JST).