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

Posted on 2006-05-26
Last Modified: 2008-01-09
how do i set the date in linux as my date and time are wrong when i check using date command
Question by:hraja77
    LVL 34

    Accepted Solution

    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
    LVL 24

    Expert Comment

    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...
    LVL 16

    Expert Comment


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

    LVL 38

    Expert Comment

    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.

    Expert Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
    The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now