Managing the date and time on a Linux system is fairly simple using the command line. Once you are familiar with the relevant command and its syntax, it is very easy to get and set the system date/time properly.
The commands shown below are tested on Ubuntu Linux but should work well on most if not all other popular variants of Linux.
The following tutorial explains.
To get the current Ubuntu system date/time, execute the following command in a terminal:
You will get the server's current date and time in the following format:
As you can see, you get the day of the week, the date, the time, the current timezone, and the year.
The command and format for setting the new system time is a bit strange and is shown below. Note that this command must be run as root:
In other words, if we want to set the date and time to September 13, 2007 9:59:32PM, we would execute the following command in a terminal as root:
And that's it. Your time is now set to what you just entered. You can check by running the date command again.
You may also want to change the timezone on your Ubuntu system using the command line as well.
We hope this Ubuntu tutorial was helpful.