Sometimes it is possible that the time on your server's internal clock does not show the correct time. This is very easy to solve by following these instructions.
Important
If your server does not have SystemD as a boot system, go to the section "GNU/Linux distributions without SystemD". This affects servers with the operating system:
- Less than Debian 8
- Less than Ubuntu 16.04
- Less than CentOS 7
We can check the clock status in Linux with this command:
# timedatectl
This will show the following output:
Local time: Wed 2022-11-02 10:47:30 CET
Universal time: Wed 2022-11-02 09:47:30 UTC
RTC time: Wed 2022-11-02 09:47:31
Time zone: Europe/Madrid (CET, +0100)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
In this output it is important to make sure that the NTP Service is active. If it is not, we can activate it as follows:
# timedatectl set-ntp true
To update the server time, we must restart a specific service:
systemctl restart systemd-timesyncd.service
This should be enough to get the time back to the correct time.
Change Time Zone
It is also possible to change the time zone, executing the following command which will display the list of zones:
# timedatectl list-timezones
And to modify it, replace <time_zone> with the desired one:
# timedatectl set-timezone <time_zone>
An example to change to the America/New_York zone:
# timedatectl set-timezone America/New_York
GNU/Linux distributions without Systemd
For Debian based distributions, to update the server clock you can use the command:
ntpdate-debian
Also, if you have manually configured an NTP server, you can restart the service:
/etc/init.d/ntp restart # O también
service ntp restart
For CentOS based distributions, to update the server clock you can use this other command:
service ntpd restart