how do i set the date in linux as my date and time are wrong when i check using date command

how do i set the date in linux as my date and time are wrong when i check using date command
Who is Participating?
Duncan RoeConnect With a Mentor Software DeveloperCommented:
There are 2 commands you need to use:
1. date, to set the date and time that Linux thinks it is, and
2. hwclock, to set BIOS CMOS data to agree with Linux

You must be running as root to use either of these to set a clock

date takes a wide variety of formats, e.g.

  date -s 10:00

sets date to 10AM today. Note the -s to get date to set time rather than simply display it.

  hwclock --systohc

Use this once you get the date right, to synchronise the BIOS clock.

To alleviate time drift in your PC, you can use adjtime. Or, better but maybe a bit trickier to set up, use ntp from a public ntp server.

Read the man pages for more information:

  man date
  man hwclock
  man adjtime
There is a good description of the operation here:

There are a few things that you need to understand like if you want to use UTC time, your timezone, etc...

What distrobution of linux are you using? because if your using Fedora or CentOS you can do

Try the command
which run on console terminal also.

However, I suggest that sync your system clock with other system by setting NTP or simply run (as root)
ntpdate -u     <=== is just one of NTP server on the internet.

Then your time is sync with the standard time.
After your system is correct, then you can run what duncan_roe's suggestion "hwclock --systohc" to make your hardware clock correct.
Assuming that your hardware clock is correctly set, you will want to ensure that in your /etc directory you have  a symbolic link to the time zone file for your region . The location of this file may vary depending on your distribution, but an easy way to find where it lives is by issuing the following: "find /usr -name CET". This will return the location of the timezone file corresponding to Central European Time (for example); you can now ls that directory and identify the file that corresponds to your region.

Noting the full path to the file (we'll use /usr/share/timezone/CET), as root issue the command: "ln -s  /usr/share/timezone/CET /etc/localtime". You should now be set up properly for your time zone.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.