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?

link|improve this question
feedback

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

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

5 Answers

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

link|improve this answer
feedback

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"
link|improve this answer
feedback

A quick search of Google returns this link:

http://www.cyberciti.biz/faq/howto-set-date-time-from-linux-command-prompt/

link|improve this answer
feedback

Set the Hardware Clock to the current System Time.

# hwclock --systohc

Set the System Time from the Hardware Clock.

# hwclock --hctosys
link|improve this answer
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown