Unix: How to Set the System’s Date and Time
The basic way to alter the system’s date in Unix/Linux through the command line environment is by using “date” command.
Using date command with no options just displays the current date and time.
By using the date command with the additional options, you can set date and time.
The following diagram shows the appropriate placeholders for each part of the command:
"man date" and "date --help"
commands reports the following syntax should be used to change system’s date:
Syntax : [MMDDhhmm[[CC]YY][.ss]]
MM = Month (01..12)
DD = Date (01..31)
hh = Hour (0..23)
mm = Minute (0..59)
[CC]YY = Year (2000..2099) #CC is Century 20 for 2000
ss = Seconds(00..60)
This means that you must at least provide two-digit values for month, day, hour
and minute for the time that you wish to set. You can also provide an optional two four or digit year and number of seconds.
Some useful examples:
$ date 11232359
# 23rd of November at 11:59pm.
$ date 112323592011
# As above, but also sets the year to 2011.
$ date 02020202.02
# 2nd of February at 02:02:02 am. No change in year.
$ date 020202022011.02
# As above, 2nd of February, at 02:02:02 am but also sets the year to 2011.
# Note here that the .02 (seconds) is preceded by a period after year 2011.
You must at least provide two-digit values.
Here are the above commands are executed in shell:
Follow the reactions below and share your own thoughts.