Differences between revisions 3 and 5 (spanning 2 versions)
Revision 3 as of 2020-11-11 15:24:25
Size: 1058
Comment:
Revision 5 as of 2023-06-29 17:09:09
Size: 1038
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= System Clock in Linux = = Linux Clock =
Line 3: Line 3:
The '''system clock''' in Linux generally uses the '''Coordinated Universal Time ''' ('''UTC''') standard, as opposed to '''localtime'''.

Linux images often come with a wonky clock setting based on when the image was generated. This can cause significant issues on web servers, as signed SSL certificates are only valid within a date range.
On Linux, the '''clock''' generally uses UTC time with a timezone offset in software, as opposed to local time.
Line 14: Line 11:
== Timezone == == Date and Time ==
Line 16: Line 13:
Use '''`timedatectl(1)`''' to set the local timezone. Use '''`date(1)`''' as the root user to set the current date and time.
Line 19: Line 16:
timedatectl status
timedatectl list-timezones
timedatectl set-timezone ZONE/SUBZONE
# January 1st, 2001 at 12:30
sudo date 0101011230
Line 24: Line 20:
`timedatectl(1)` is a simple utility script; the manual equivalents roughly are...

{{{
realpath /etc/localtime
ls /usr/share/zoneinfo/*
ln -sf /usr/share/zoneinfo/Zone/SubZone /etc/localtime # apply a new setting
}}}
Use '''`hwclock(1)`''' or [[TimeDateCtl|timedatectl(1)]] to check the CMOS clock.
Line 36: Line 26:
== Date == == Timezone ==
Line 38: Line 28:
Use '''`date(1)`''' to set the current datetime. Note that `date(1)` must be called by the root user to set a datetime. The configured timezone is set in `/etc/localtime`. By standard convention, this should be a symbolic link to a pre-prepared file, typically under `/usr/share/zoneinfo`.

To check the current configuration, try:
Line 41: Line 33:
# January 1st, 2020 at 12:30
sudo date 2001011230
realpath /etc/localtime
}}}

To change the configuration, try:

{{{
ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime
}}}

For `systemd`-capable systems, consider using [[TimeDateCtl#Timezone|timedatectl(1)]].

Some utilities will also respect a `TZ` environment variable.

{{{
export TZ=America/New_York
date

Linux Clock

On Linux, the clock generally uses UTC time with a timezone offset in software, as opposed to local time.


Date and Time

Use date(1) as the root user to set the current date and time.

# January 1st, 2001 at 12:30
sudo date 0101011230

Use hwclock(1) or timedatectl(1) to check the CMOS clock.


Timezone

The configured timezone is set in /etc/localtime. By standard convention, this should be a symbolic link to a pre-prepared file, typically under /usr/share/zoneinfo.

To check the current configuration, try:

realpath /etc/localtime

To change the configuration, try:

ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime

For systemd-capable systems, consider using timedatectl(1).

Some utilities will also respect a TZ environment variable.

export TZ=America/New_York
date


CategoryRicottone

Linux/Clock (last edited 2023-06-29 17:16:15 by DominicRicottone)