skip navigation

www.Hilands.com


Content:: Changing the time and date via command line :: www.hilands.com

We can use the "date" command to change the date via command line in Linux.

I prefer using the format controls just in case the flavor of Linux plays different. You can get a list of the format controls by viewing the man page. man date

Using the controls lets change the time.
We can use the format %T which is the same as %H:%M:%S or Hours:Minutes:Seconds.
We will "set" the date with the -s(--set) switch.
The time format is in military time, setting it to 15:15:15 will set it to 3:15:15 pm. date %T -s "15:15:15" To change the date we will use the %Y - for the full year, %m for the two digit month, %d for the two digit day.
Again we will use the -s(--set) switch to "set" the date.
This format will set the date to January 18th 2038 date %Y%m%d -s "20380118"
Last Modified: 2012-10-08