Differences between revisions 2 and 6 (spanning 4 versions)
Revision 2 as of 2020-11-11 15:14:59
Size: 1339
Comment:
Revision 6 as of 2023-06-29 17:16:15
Size: 1161
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was renamed from SystemDateSetup
= System Date =
= Linux Clock =
Line 4: Line 3:
Linux distros often come with a wonky system date--both in the past (i.e., when the image was generated) and in a different timezone (usually GMT). 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 6: Line 5:
Set the timezone before trying to set the date. <<TableOfContents>>

----



== 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|timedatectl(1)]] to check the CMOS clock.
Line 14: Line 28:
The easy-to-use tool for setting timezones is `timedatectl`. 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 17: Line 33:
timedatectl status # observe current setting
timedatectl list-timezones # observe available settings
timedatectl set-timezone Zone/SubZone # apply a new setting
realpath /etc/localtime
Line 22: Line 36:
This is just a wrapper around `ln` however. The manual process is: To change the configuration, try:
Line 25: Line 39:
realpath /etc/localtime # observe current setting
ls /usr/share/zoneinfo # observe available zones
ls /usr/share/zoneinfo/Zone # observe available subzones
ln -sf /usr/share/zoneinfo/Zone/SubZone /etc/localtime # apply a new setting
ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime
Line 31: Line 42:
---- For [[Linux/Debian|Debian]]-based distributions, consider using the interactive '''`dpkg-reconfigure tzdata`''' script.
Line 33: Line 44:
For `systemd`-capable systems, consider using [[TimeDateCtl#Timezone|timedatectl(1)]].
Line 34: Line 46:

== Date ==

The system date is set using the standard `date` utility, run as the superuser with an argument.
Some utilities will also respect a `TZ` environment variable.
Line 40: Line 49:
sudo date 2001011230 # sets system date to January 1st, 2020 at 12:30 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 Debian-based distributions, consider using the interactive dpkg-reconfigure tzdata script.

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)