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. Returnsnull if input is invalid. Returns original date if timezone format is invalid.
Examples
Example 1: Convert UTC to Eastern Time
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
nullfor 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
- date.format - Format date with timezone support
- date.parse - Parse date with timezone context
- date.truncate - Truncate date to specific unit
Frequently Asked Questions
What does flex.date.toTimeZone do?
What does flex.date.toTimeZone do?
It converts a date/time value to a different timezone by applying an offset, returning the adjusted date/time.
How do I specify the timezone offset?
How do I specify the timezone offset?
The offset is specified as a numeric value representing hours (e.g.,
-5 for EST, +9 for JST).