Setting Linux time and time zone

From RidgeRun Developer Connection
Jump to: navigation, search

Set Time

The system time can be set from C using stime or settimeofday and from the command line sing the date command (date MMDDHHMMYYYY).

Running “date” or “date --utc” you can get the current system time in local time and Coordinated Universal Time (UTC) respectively.

Local time is being affected by the time zone configured.

Set Time Zone

The GNU C Library includes a time zone database that contains time information for most regions of the world. Also you can find independent zone time databases like http://www.iana.org/time-zones. Linux stores zone time information at /usr/share/zoneinfo.

There are two ways to define the time zone:

  • Set the "TZ" environment variable. However with this approach the time zone change will only be visible for the shell or application that sets the variable. The variable TZ can be set on different formats, see Specifying the Time Zone with TZ. Following some examples of how to set "TZ" from the comandline:
export TZ=UTC-6
  • Create a symbolic link called /etc/localtime that points to the appropriate time zone file in the database. This can be done from C using symlink or from the cmdline as follows:
ln -sf /usr/share/zoneinfo/America/Costa_Rica /etc/localtime

References

  1. GMT vs UTC
  2. Specifying the Time Zone with TZ
  3. Setting Linux System Time, Date, and Time Zone