Linux Date command View and set time detailed

Source: Internet
Author: User
Tags set time

Date command

The function of the date command is to display and set the system date and time.

The general format for this command is: date [options] Displays the time format (beginning with +, followed by formatting)

Date set time format

The meanings of the options in the command are:

The code is as follows:

-D datestr,--date DATESTR displays the date described by datestr

-S Datestr,--set datestr set datestr description of the date

-U,--universal Show or set Universal Time

Time Domain

The code is as follows:

% H hours (00..23)

% I-hour (01..12)

% K hours (0..23)

% L-hour (1..12)

% M min (00..59)

% p displays am or PM

% R Time (Hh:mm:ss am or PM), 12 hours

% s number of seconds from January 1, 1970 00:00:00 to current experience

% S sec (00..59)

% T Time (24-hour system) (HH:MM:SS)

% X shows the format of the time (%h:%m:%s)

% Z time zone Date field

% a weekday abbreviation (Sun.. Sat)

% A week's full name (Sunday). Saturday)

The abbreviation of the% B-month. DEC)

The full name of the% B-month (January). December)

% c date and time (Mon Nov 8 14:12:46 CST 1999)

% d One months of the first days (01..31)

% D Date (MM/DD/YY)

% h and%b options are the same

% J The first day of the Year (001..366)

% m month (01..12)

% W one week of the first day (0 for Sunday)

% W The first few weeks of the year (00..53, Monday for day one)

% x shows the format of the date (MM/DD/YY)

The last two digits of the Y-year (1999 is 99)

% Y year (for example: 1970,1996 etc.)

Note: Only Superuser has permission to set the time using the Date command, and the average user can only display the time using the date command.

Show date and time

Under the character interface, in addition to displaying years, users can also use the "date" command to display and set the system date and time. Specifically, only Superuser can set the time with the "date" command, and the average user can only display time with the "date" command.

Displays the time in the specified format, with the following command:

Where% x shows the format of the date (MM/DD/YY) and% x shows the format of the time (%h:%m:%s).

Other parameters to view the settings for the Date Time field above.

Example:

code example:

Set time to 9:16 A.M.

The order is as follows:

# date-s 09:16:00

Set the time to August 1, 2013

The order is as follows:

# date-s 130801

Where-S is the parameter that sets the date.

Set time for August 1, 2013 9:16 A.M.

The order is as follows:

# date-s ' 09:16:00 2013-08-01 '

Where-S is the parameter that sets the date.

Get the date format for the day in the shell script, as follows:

The use of other parameters of the date command is not exhaustive, such as%h display hours (00..23),%m display points (00..59),%p display AM or PM,%s display seconds (00..59), and%z display time zone, and so on.

We can study it by ourselves.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.