Skip to content

time_zone

The time_zone filter is designed to convert a date/time value from one time zone to another. This is essential for displaying dates and times correctly for users in different locations.

Functionality

  • Date/Time Values: Takes a date, time, or datetime value as input.
  • Target Time Zone: Requires a string argument specifying the target time zone to convert to.
    • You can use standard time zone names (e.g., "America/Chicago", "Europe/London") or the special value "local" to convert to the time zone associated with the current request context.
  • Conversion: Converts the input date/time from its original time zone to the specified target time zone.
  • Output: Returns a new datetime value representing the date/time in the target time zone.

Syntax

Code snippet

    {{ input_datetime | time_zone: target_zone }}

Arguments

  • target_zone: A string specifying the time zone to convert to (e.g., "America/New_York", "UTC", "local").

Code Samples

Example 1: Converting to a Specific Time Zone

Code snippet

    {% assign event_time = "2024-05-22T10:00:00-04:00" | date: "%Y-%m-%dT%H:%M:%S%z" | date: "%Y-%m-%dT%H:%M:%S%z"  %}

    {{ event_time | time_zone: "Europe/Paris" }}

Output:

2024-05-22T16:00:00+02:00
Example 2: Converting to the Local Time Zone

Code snippet

    {% assign meeting_time = "2024-05-22T12:30:00Z" | date: "%Y-%m-%dT%H:%M:%S%z" | date: "%Y-%m-%dT%H:%M:%S%z" %}

    {{ meeting_time | time_zone: "local" }} 

Output: (Assuming the local time zone is CDT)

2024-05-22T07:30:00-05:00
Example 3: Invalid Time Zone

Code snippet

    {% assign now = "now" | date: "%Y-%m-%dT%H:%M:%S%z" | date: "%Y-%m-%dT%H:%M:%S%z"  %}

    {{ now | time_zone: "Invalid/Timezone" }}

Output: (Might return the original datetime or an error, depending on Experience Builder's handling)

2024-05-22T09:05:34-05:00
Outliers and Special Cases

  • Invalid Time Zone: If the target_zone is not a recognized time zone identifier, the filter might return the original value or throw an error.
  • Non-Date/Time Input: If the input is not a date, time, or datetime value, the filter might attempt to convert it or return an error.
  • Daylight Saving Time: The filter should automatically handle daylight saving time adjustments based on the specified time zone.

Key Points

  • The time_zone filter is crucial for displaying accurate times to users across different time zones.
  • Use standard time zone names for reliable conversions.
  • Test your conversions with different time zones and dates to ensure correct behavior, especially around daylight saving time transitions.