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

how to change date in linux

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

 

https://services.vlitag.com/vpaid/?q=9ba3f2539ddb6b2df45a4f25fbfd7843&defaultVolume=&page_url=https://linuxtechlab.com

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.

 

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter

Linux TechLab is thankful for your continued support.