Translation(s): English - Italiano - Português (Brasil)
Contents
View the current time
To see the time on a Debian GNU/Linux system, use the command date without arguments. It will show system time respecting the currently defined timezone.
To see the time in the UTC timezone, use the command date --utc (or its shorthand, date -u). See the date manual page.
Setting the time manually
When setting the system time manually using date directly, the required time specification format may be confusing (by POSIX convention has to be MMDDhhmmYYYY). However, when using the --set argument, date accepts the date and time in many formats. You can read date' manual page, or use the example below for one possible and very useful format. The --set argument examples below are specified in the ISO 8601 standard's extended format as YYYY-MM-DD for Year-Month-DayOfMonth, and time of day HH:MM:SS using 24 hour clock. Leading zeros are significant.
date --set 1998-11-02 date --set 21:08:00
The above two commands set the system date to second of November, 1998, and system time to eight minutes past nine, PM.
Note: using the date command only sets the runtime system time (aka. software clock) but has no effect on the underlying hardware clock (aka. RTC = real time clock). When the system boots, it has no concept of absolute time and will populate the system time with the date and time read from the hardware clock, thus to ensure that the time set using date is kept across reboots it has to be saved to the hardware clock.
Most desktop environments provide a date/time configuration utility. See also the time-admin program in gnome-system-tools package.
Setting the hardware clock
To write the current system time to the hardware clock so that it can be recovered on subsequent restarts of the system, correct the system time as above, then use the command hwclock --systohc to save it to hardware (see the hwclock manual page for more options).
Modern Debian releases (2.2 and onwards) automatically save the system time to hardware clock on proper shutdowns, and set the system clock from hardware clock when they boot up. This is done by the script /etc/init.d/hwclock.sh.
Setting the time automatically
The protocol used to set the time is the Network Time Protocol or NTP. To set the time automatically you need access to an NTP server. Your local network may provide such a server but most people will access an NTP server via the internet.
On the internet there are time servers that provide the correct time. Your ISP may provide a time service and this would be your closest and probably most accurate source. While there are many independent NTP servers you can connect to, the best source is http://pool.ntp.org.
Installing NTP Clients
Debian provides several packages to install a NTP client, depending on the version of the operating system. Since Debian 12, the default NTP client is Systemd's systemd-timesyncd.
You can use chrony, ntp or ntpsec with Systemd. As of Debian 12, ntp was replaced by ntpsec; see Changes to packages that set the system clock. Systemd does not require you to run systemd-timesyncd.
chrony package
chrony is an independent NTP implementation licensed under GNU GPL v2.
Perform the following to install chrony:
apt-get install chrony
To configure the chrony package, you should modify /etc/chrony/chrony.conf.
ntp package
ntp is a port of the original reference implementation.
Perform the following to install ntp:
apt-get install ntp
To configure the ntp package, you should modify /etc/ntp.conf.
ntpsec package
ntpsec is a security hardened fork of the reference implementation. On Debian Bookworm (and later) NTP is a transitional package to ntpsec.
Perform the following to install ntpsec:
apt-get install ntpsec
To configure the ntpsec package, you should modify /etc/ntpsec/ntp.conf
systemd-timesyncd
systemd-timesyncd is Systemd's implementation of the SNTP protocol. If Systemd is installed, you can enable the NTP client using sudo timedatectl set-ntp true.
To configure timesyncd, you should modify /etc/systemd/timesyncd.conf.
Managing NTP Pools
You can use more local sources. Change the server pool.ntp.org line to server XX.pool.ntp.org, where XX is your continent or two letter country code.
For increased accuracy you can include extra server lines such as
server 0.XX.pool.ntp.org server 1.XX.pool.ntp.org server 2.XX.pool.ntp.org
Increment the number for each line you add to the file.
You must use at least 3 time sources when using a pool. As the saying goes, A person with a watch knows what time it is. A person with two watches is never sure.
Windows Dual Boot Strategy
If your machine dual boots Windows and Linux, then you could have problems because Windows uses localtime for the hardware clock; while Linux and Debian use UTC for the hardware clock. In this case you have two choices. The first is to use localtime for the hardware clock, and set Debian to use localtime. The second is to use UTC for the hardware clock, and set Windows to use UTC.
If given a choice, you should prefer the second option of using UTC because UTC does not suffer daylight savings time and time zone changes while traveling. A hardware clock configured for UTC will monotonically increase, and not jump around due to daylight savings time and time zone changes.
Hardware Clock in localtime
If the machine's hardware clock is in localtime, then you should modify Debian's configuration. Debian uses the file /etc/adjtime to hold hardware clock timezone information:
0.000000 14602224559 0.000000 1460224559 UTC
To change the setting, edit the file /etc/adjtime and change "UTC" to "LOCAL" using your favorite editor. You must use sudo or su to edit the file.
Hardware Clock in UTC
If the machine's hardware clock is in UTC, then you should modify Windows' configuration. Windows uses the registry to store hardware clock timezone information. The default value is localtime if the registry key is missing.
To change the setting, run regedit as an administrator. Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation. Create a key named RealTimeIsUniversal with type QWORD, and set the value to 1.
External References
8.9. Other Configurations: Time Synchronization, Logs, Sharing Access… - The Debian Administrator's Handbook