Linux – How to set current time on Linux


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

And can I change the current time on Linux?

Best Answer

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"
Related Question