Unix: Date & time


Gnu/Linux provides commands that let you set the current system date and time and the system time zone.


To display the current system time, enter the date command:

$ date
Sun Mar 16 09:28:22 CEST 2014

To set the system time, you specify the new time using the following format: MMDDhhmm[YYYY.ss], where MM is month, DD is day of the month, hh is hour, mm is minute, YYYY is year, ss us second. (the year and second are optional). Example:

# date 031609282014.22
Sun Mar 16 09:28:22 CEST 2014


When you power down or reboot your system, the system date & time will revert to the date & time values held in non-volatile (CMOS) memory. If this clock is wrong, the system date & time will be wrong after a reboot.

To store the current system date and time in CMOS, issue the following command:

# hwclock --systohc


The current system timezone is a string that is stored in a file named /etc/timezone. To inspect the timezone, list this file:

# cat /etc/timezone

To set the time zone, write a new valid string to this file, and use the command dpkg-reconfigure to set it noninteractively.

# echo "Europe/Oslo" > /etc/timezone
# dpkg-reconfigure -f noninteractive tzdata

Be aware that running processes may not pick up the change without a restart. In particular: log timestamps from server daemons are likely to be wrong until you restart the daemons.


Command Meaning
date print or set system date & time
hwclock query or set the hardware clock