HomeUNIXLinuxUnix: How to Set the System's Date and Time

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:

Date Command Syntax Linux Unix
"man date" and "date --help"

commands reports the following syntax should be used to change system’s date:

Syntax : [MMDDhhmm[[CC]YY][.ss]]
where,
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:

Example Date command Linux/Unix

Vishwanath Dalvi
Vishwanath Dalvi
Vishwanath Dalvi is a gifted engineer and tech enthusiast. He enjoys music, magic, movies, and gaming. When not hacking around or supporting the open source community, he is trying to overcome his phobia of dogs.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments

Cleveland Furia on How to Clear Google Activity
Sid Wohlfarth on How to Clear Google Activity
Riley Magsayo on How to Clear Google Activity
สมัครรับเครดิตฟรี ทันที on How to improve Remote Desktop Protocol Performance
Neal Wangstad on How to Clear Google Activity
Slavcho Andov on How to install Ubuntu
Slavcho Andov on How to fix bad sectors
Sheraz Ali on How to Backup Android