If you missed to set the proper timezone, date and time while installing the OS. Don’t worry it can be changed at any point of time.
If we bought the server from some providers and they might have set the timezone based on their location.
Say for example, if you buy a server from USA then they will build a system based on their GEO location.
If so, don’t worry you can simply change the timezone and date formats as per your requirement using the below commands on your Linux Box.
In this article, i have covered all the possible methods with all Major Linux Distribution such as CentOS, Redhat (RHEL), Fedora, Ubuntu, Debian, Mint & openSUSE systems.
Also, we have updated the information based on the system manager such as SysVinit and systemd. Timezone is controlled by /etc/localtime
file.
The below files are belongs to timezone on Linux.
/usr/share/zoneinfo:
This directory contains timezone files./etc/localtime:
This file is symlink with timezone file./etc/timezone:
This file is holding timezone name on debian based systems./etc/sysconfig/clock:
This file is holding timezone name on RHEL based systems.
1) How To Check Current Date, Time And Timezone Information In Linux?
Use the following commands to check the current date, time and timezone information in Linux systems.
To check current system date and time.
# date Fri Apr 5 09:32:38 CDT 2019
To display current system date and time with UTC format.
# date -u Fri Apr 5 14:32:54 UTC 2019
Run the following command to display Hardware Clock (RTC).
# hwclock --show Fri 05 Apr 2019 14:33:13 PM UTC -1.027744 seconds
To check the timezone on SysVinit systems.
# date Fri Apr 5 09:32:38 CDT 2019 [For Details] # ls -lh /etc/localtime lrwxrwxrwx. 1 root root 37 Feb 19 06:08 /etc/localtime -> ../usr/share/zoneinfo/America/Chicago
We can sell all the details together in the single command for systemd systems. See the details below.
# timedatectl Local time: Fri 2019-04-05 09:37:57 CDT Universal time: Fri 2019-04-05 14:37:57 UTC RTC time: Fri 2019-04-05 14:37:56 Time zone: America/Chicago (CDT, -0500) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: yes Last DST change: DST began at Sun 2019-03-10 01:59:59 CST Sun 2019-03-10 03:00:00 CDT Next DST change: DST ends (the clock jumps one hour backwards) at Sun 2019-11-03 01:59:59 CDT Sun 2019-11-03 01:00:00 CST
2) How To Set/Change Date And Time In SysVinit Systems?
Use the following commands to set or change the time and date as you wish in Linux SysVinit systems. If you requires locale’s then you can set accordingly.
Common Syntax:
# date --set="STRING"
To set new date and time in one shot, use the following format.
# date --set="6 Apr 2019 11:30:00" Sat Apr 6 11:30:00 CDT 2019
You can double confirm this by running date
command once again.
# date Sat Apr 6 11:30:04 CDT 2019
To set only time, use the following format.
# date +%T -s "10:00:00" 10:00:00
To set only date, use the following format.
# date +%Y%m%d -s "20190409" 20190409 # date Tue Apr 9 00:00:02 CDT 2019
To Set time with locale’s.
# date +%T%p -s "01:15:00AM" 01:15:00AM
To set the hardware clock to local time.
# hwclock --set --date="2019-04-06 11:30:00" --localtime
To set the hardware clock to UTC time.
# hwclock --set --date="2019-04-06 11:30:00" --utc
3) How To Set/Change Date And Time In systemd Systems?
Use the following commands to set or change the time and date as you wish in Linux systemd systems.
Common Syntax:
# timedatectl set-time YYYY-MM-DD HH:MM:SS
To change the new date and time in one shot, use the following format.
# timedatectl set-time '2019-04-07 08:30:10'
To set only time, use the following format.
# timedatectl set-time '09:45:20'
To set only date, use the following format.
# timedatectl set-time '2019-04-10'
Use the following format to set RTC time.
# timedatectl set-local-rtc 0
4) How To Change The TimeZone In systemd Systems?
For systemd system, use the timedatectl
command to change the timezone. Navigate to the following url to change the timezone in Linux.
$ sudo timedatectl set-timezone America/Chicago
If you would like to restart the timedatectl service, use the following command.
# systemctl restart systemd-timedated
Run the following command to verify the new timezone.
# timedatectl
Local time: Tue 2019-02-19 06:08:15 CST
Universal time: Tue 2019-02-19 12:08:15 UTC
RTC time: Tue 2019-02-19 12:08:15
Time zone: America/Chicago (CST, -0600)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: no
Last DST change: DST ended at
Sun 2018-11-04 01:59:59 CDT
Sun 2018-11-04 01:00:00 CST
Next DST change: DST begins (the clock jumps one hour forward) at
Sun 2019-03-10 01:59:59 CST
Sun 2019-03-10 03:00:00 CDT
5) How To Change The TimeZone In RHEL 6/CentOS 6 Systems?
For RHEL/CentOS systems, use the following command to change the timezone.
# unlink /etc/localtime
# ln -s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
Run the following command to check the new timezone in RHEL/CentOS systems.
# date Tue Feb 19 04:17:00 PST 2019 # ls -lh /etc/localtime lrwxrwxrwx. 1 root root 39 Feb 17 10:45 /etc/localtime -> /usr/share/zoneinfo/America/Los_Angeles
6) How To Automatically Adjust Your Linux System Clock?
If you would like to sync your Linux system clock to remote NTP server then you have configure it.
To do so, navigate the following urls because we had written an detailed articles about these in the past.
- How To Install And Configure NTP Server And NTP Client In Linux?
- How To Install And Configure Chrony As NTP Client?
I am using redhat 4.0 and command ln -sf /usr/share/zoneinfo/UTC /etc/localtime works for me the first time but now no longer works for me.
I have not a file /etc/zonetime
and change the file: nano /etc/sysconfig/clock ZONE=”Etc/UTC”
and make all of these changes on the server, but the system still gives me the wrong time zone
If you added the timezone @ /etc/sysconfig/clock, it won’t revert back while rebooting.
Thanks this article is very helpful and i have changed the timezone.