Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Why is the output of the following commands different?

root@vmi2115:/var# hwclock
Sun 26 Jun 2011 01:21:38 PM CEST  -0.273230 seconds
root@vmi2495:/var# date
Sun Jun 26 15:21:39 CEST 2011
root@vmi2115:/var# 

And can I change the current time on Linux?

share|improve this question

migrated from stackoverflow.com Jun 26 '11 at 13:28

This question came from our site for professional and enthusiast programmers.

    
A quick search of Google returns this link: > cyberciti.biz/faq/howto-set-date-time-from-linux-command-prompt –  sparkymat Jun 26 '11 at 13:26

7 Answers 7

Usually you'll want to have the time set automatically, and in that case, you'll want to set up ntpd to automatically set the time for you.

The specifics differ slightly from distribution to distribution, but if you're running Ubuntu, for instance, there's a guide on setting up NTP on Ubuntu. Otherwise, just Google ntpd <distribution-name>, and you'll probably find it.

If you want to set it manually, however, you can use date --set="<date string>". Examples of this could be:

date --set="23 June 1988 10:00:00"
date --set="10:00:00"
share|improve this answer

Set the Hardware Clock to the current System Time.

# hwclock --systohc

Set the System Time from the Hardware Clock.

# hwclock --hctosys
share|improve this answer

just ntpdate ntp.ubuntu.com and everything will be fine.

share|improve this answer
10  
please elaborate further on your answer and supply an explanation to the QA and future readers what does the command you mentioned do and why you recommend such action. note: the QA asked how to change the time, not how to keep it synced. –  Lorenzo Von Matterhorn Apr 1 '13 at 13:55
1  
@LorenzoVonMatterhorn ok –  Gangsar Swa Purba Apr 5 at 0:40
    
This still has no explanation. What should I expect to happen if I run this command? –  jeremyclarke Oct 2 at 17:19
    

Check your timezone. hwclock may return GMT time, whileas date returns local time, afaik.

share|improve this answer
    
This isn't very helpful. How do we solve the problem or even interpret the output? –  jeremyclarke Oct 2 at 17:19

Another common, very annoying problem is, when the wrong timezone is selected...

Check the timezone with the date output:

$ date

Fre Aug 23 18:47:04 UTC 2013

to correct timezone:

$ sudo tzselect and select the correct Region with the corresponding numbers.

Second task is to set the correct time:

$ sudo date --set="18:37:00"

Or simply take the time from the HW-Clock:

$ sudo hwclock --hctosys

share|improve this answer

date return the time given as the time from the moment the cpu started plus the internal hardware clock given time, hwclock gives the time the internal clock has.

The cpu based time tend to drift the long the machine is up, that is the reason behind the existence of hwclock --hctosys command. Also is one of the reasons behind the the use of the Network Protocol Time, which is used to coordinate time internationally on the internet.

share|improve this answer

"hwclock" is date of hardware (machine), and "date" is date of software (operative system).

For change pc hardware date:

hwclock --set --date="2013-7-31 09:30"

For change software date:

date --set "2013-7-31 09:30"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.