n this tutorial, we are going to discuss how to change date in Linux. We are going to discuss 3 commands which we can use to view/modify the date & time for our systems. Before we discuss the commands, let’s learn in brief about two different types of clocks available i.e. system clocks & Hardware clocks,
System clock or software clock is maintained by OS, the kernel in particular & is initialized when your system boots up while the Hardware clock or Real-time clock (RTC) is independent of the OS & works even when the system is closed. It draws power from the BIOS battery to continue working. Now let’s move onto the commands which we will use to work with these clocks.
- timedatectl command – was introduced as a part of systemd in version 7 of RHEL/CentOS. It allows us to change/view the system clock.
- date command- is available for all the Linux distributions & is used to change the date in Linux systems.
- hwclock command – is used for accessing the hardware clock of the system& is used for displaying time from the hardware clock
Recommended Read: 5 ways to add or change hostname in CentOS 7
Also Read: IP Route command: Create static routes or Change the default Gateway in Linux
How to change DATE & TIME in Linux
TIMEDATECTL command
Display Date & Time
To view the current date & time of your system clock, run
$ timedatectl
Changing Time
To change the time of the system clock, run
$ timedatectl set-time HH:MM:SS
Where HH means hour, MM means minutes & SS means seconds.
Changing Date
To change the date of the system clock, run
$ timedatectl set-time ‘YYYY-MM-DD HH:MM:SS’
Where YYYY is the year, MM is the month & DD is the day of the month. We also need to specify the time otherwise it will be set as 00:00:00.
Changing time-zones
Firstly to change the time-zone of a system clock, we need to find the time-zone that we need to set. To find the time zone, run
$ timedatectl list-timezones
It will display the list of available time-zones. Select the zone & run the following command to set it,
$ timedatectl set-timezonetime_zone (Asia/dhaka).
DATE command
Display Date & Time
To view the current date & time of your system clock, run
$ date
We can also customize the display date format using,
$ date +”MM:HH:SS”
Changing Time
To change the time of the system clock, run
$ date +%T –s “HH:MM:SS”
It will set the time in 24-hour format. To use time in AM/PM format, use
$ date +%T%P –s “HH:MM:SSAM”
Changing Date
To change the date of the system clock, run
$ date –s ‘DD MM YYYY HH:MM:SS’
To set the date in a customized format, use
$ date %y%m%d –s “YYYYMMDD”
HWCLOCK command
Display Date & Time
To view the current date & time of your Hardware clock, run
$ hwclock
Changing Date &Time
To change the time of the Hardware clock, run
$ hwclock --set --date “DD MM YYYY HH:MM”
Synchronizing Date & Time
To synchronize Hardware clock to system clock, run
$ hwclock --systohc
Or to synchronize system clock to hardware clock,
$ hwclock --hctosys
These were some commands on how to change date in Linux & the time of your machine. If you have some queries/issues regarding the above, please leave them in the comment box below.
Dear Sir
I want to know how i can change date and time permanently means If i will restart my server it should not be change it should remains same as befor.
All these commands are used to send date permanently only. If your server is getting reset to an old date and time, then its probably because of an old CMOS battery.
What is the point of timedatectl? What does it do that date does not?
Yes date command also accomplishes the same but like other commands timedatectl is in line with systemd that was introduced with RHEL 7.
So be prepared for future as all the old commands would be deprecated.
I see. Change something that works perfectly just because we can.
Well that’s what i think but its not you & me that are incharge of development there.
How to change Time format from 24 hour to permanent 12 hour format in centos 7 server.
Assume you are using GNOME, please try the following. Execute the following command from terminal,
$gsettings range org.gnome.desktop.interface clock-format
\enum
\’24h’
\’12h’
To use the GUI tools, try right clicking on the Clock applet and change the settings from there.
How to check the last “date” change in Redhat6?
you can only check if a command was executed from history. & if you need time as well, than you need to have HISTTIMEFORMAT variable enabled for the history command.
You can do so by running the following command,
export HISTTIMEFORMAT=’%F %T ‘
very helpful topic
The date command on my centos 7.5 system returns the below response
Tue Jan 22 11:28:41 +08 2019
Is there a way to change the “+08” to “GMT+08” ? I have tried changing using the date and timedatectl command, but no luck so far.
Hi,
Is there a way to change the default clock format in Centos 7 from 24h to 12h
example:
Thu Jan 24 17:00:13 PST 2019 to Thu Jan 24 05:00:13 PM PST 2019
Thank you
Can you change the Date/Time as a non-sudo account?
no, you can’t.