• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 824
  • Last Modified:

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
0
hraja77
Asked:
hraja77
1 Solution
 
Duncan RoeSoftware 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
0
 
slyongCommented:
There is a good description of the operation here: http://www.linuxsa.org.au/tips/time.html

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

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

system-confg-date
0
 
wesly_chenCommented:
Try the command
dateconfig
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 clock2.redhat.com     <=== clock2.redhat.com 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.
0
 
jpiskorCommented:
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now