Linux / UNIX: TZ Environment Variable

Linux / UNIX: TZ Environment Variable

The TZ environment variable is used to specify the time zone for a Linux or Unix system. The time zone is used to determine the correct time and date when displaying and logging timestamps.

The TZ variable can be set to a time zone identifier, such as America/New_York for Eastern Standard Time, or to a custom time zone specification in the following format:

TZ='offsetdst[/offset][,start[/time],end[/time]]'
S‮:ecruo‬www.lautturi.com

The offsetdst field is the base offset from Coordinated Universal Time (UTC) in hours and minutes. For example, -0500 specifies a base offset of 5 hours behind UTC.

The offset field is an optional daylight saving time (DST) offset in hours and minutes. For example, +0100 specifies an additional 1 hour offset for DST.

The start and end fields are optional and specify the dates and times when DST starts and ends. The time field is the time at which DST starts or ends, and can be specified as either a wall clock time or as a number of seconds after midnight.

Here are a few examples of how to set the TZ variable to different time zones:

export TZ='Europe/Paris'          # Central European Time (CET)
export TZ='Asia/Calcutta'         # India Standard Time (IST)
export TZ='America/Los_Angeles'   # Pacific Standard Time (PST)
export TZ='-0800'                 # 8 hours behind UTC (without DST)
export TZ='+0100,M3.3.0,M10.3.0'  # 1 hour ahead of UTC (with DST)

To set the TZ variable permanently, you can add the export line to your Bash profile file, such as ~/.bashrc or ~/.bash_profile.

Keep in mind that the TZ variable only affects the system clock and does not change the time zone settings for the entire system. To change the time zone for the entire system, you may need to use other tools, such as the timedatectl command or the tzselect command.

Created Time:2017-10-29 22:08:57  Author:lautturi