To view the current date and time, the following command will be enough
To change time means to set a new time. To set time in Ubuntu (or any Linux), just run the following command
sudo date newdatetimestring
where newdatetimestring has to follow the format nnddhhmmyyyy.ss which is described below
- nn is a two digit month, between 01 to 12
- dd is a two digit day, between 01 and 31, with the regular rules for days according to month and year applying
- hh is two digit hour, using the 24-hour period so it is between 00 and 23
- mm is two digit minute, between 00 and 59
- yyyy is the year; it can be two digit or four digit: your choice. I prefer to use four digit years whenever I can for better clarity and less confusion
- ss is two digit seconds. Notice the period ‘.’ before the ss.
Let’s say you want to set your computer’s new time to December 6, 2007, 22:43:55, then you would use:
sudo date 121710452006
sudo date 120622432007.55
where 12 is the month, 17 is the day, 10 is the hour, 45 is the minute, and 2006 is the year!
Change Time Zone
You may update or change your time zone by
This command will guide you through the process of setting a new time zone. You may also choose UTC (GMT) if you want.
If your system does not have tzconfig, you may use something else.
This will provide a set of different time zones to choose. If you would like to set the time to UTC, choose the option which says something like ‘none of the above’, or ‘none of these’ or something to this effect. In my case it was option 11. Then it asks for difference from UTC (GMT and GST is also the same thing). I chose GST-0 as the option and it set the time as UTC.
Sync Clock Via NTP
If you want to sync your clock with NTP servers, it is also very easy. Just make sure you have the file ntp.conf file in /etc. How can you check it?
If you see
/etc/ntp.conf as a result, you already have that file. If the ls command gives an error, you do not have it. If so, you may create it yourself.
sudo vim /etc/ntp.conf
This file will be used to automatic synchronization of the clock. I do not know if the client uses this file automatically or one has to configure something first.
Whether you have the file already or not, make sure it has at least the following data
Here you may replace, add, and/or remove any servers you wish. You will find a list of time servers from the public NTP time server list.
You may manually sync the clock using the following
sudo ntpdate servername
where servername can be any public or private time server. You may always choose the following without hesitation
sudo ntpdate pool.ntp.org