function::tz_gmtoff - Linux


The tz_gmtoff command retrieves the offset of local time from Coordinated Universal Time (UTC) in seconds. This offset typically includes information about daylight saving time (DST). It is commonly used to adjust timestamps stored in UTC to the local time zone or to calculate the time difference between locations in different time zones.


tz_gmtoff [--help]


| Option | Description | Default |
| --help | Display usage information and exit | – |


Example 1: Get the UTC offset for the current time zone:

$ tz_gmtoff

Example 2: Adjust a UTC timestamp to local time:

$ date -d "$(date +%s) + 21600"
Tue Jan 10 18:00:00 PST 2023

Example 3: Calculate the time difference between two locations:

$ tz_gmtoff -3600 - 21600

Common Issues

Potential Error:

  • tz_gmtoff: invalid time zone


  • Ensure that the time zone used as an input is valid.


Example Script:

The following script converts UTC timestamps in a file to local timestamps:


# Get the UTC offset in seconds

# Convert the timestamps in the file
while read line
    timestamp=$(echo "$line" | cut -d' ' -f1)
    local_timestamp=$((timestamp + utc_offset))
    echo "$local_timestamp $(echo "$line" | cut -d' ' -f2-)"
done < input.txt

Related Commands

  • date: Display or set the current date and time
  • timezonectl: Manage system time zones