Use the date command under Linux to view and set time

xiaoxiao2021-03-06  15

Use the date command under Linux to view and set time

Use the date command under Linux to see and set the time. It is quite convenient. This article details the use of DATE.

Date command

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

The general format of this command is: Date [option] Display time format (starting with start, rear connection format)

Date Setting Time Format

The meaning of each option in the command is:

-d datestr, --Date dateStr Display the date described by DateStr

-S dateStr, --Set dateStr Set the date of DateSTR description

-u, --universal display or set up a general time

Time domain

% H hours (@..23)

% I hour (01..12)

% K hours (0..23)

% l Hours (1..12)

% M points (00..59)

% P shows AM or PM

% R Time (HH: MM: SS AM or PM), 12 hours

% s from

1970

year

1

month

1

day

00:00:00 to the number of seconds experienced

% S second (00..59)

% T Time (24-hour) (HH: mm: SS)

% X Display Time Format (% H:% M:% S)

% Z time zone date domain

% a short story (Sun..SAT)

% A "Sunday..SATURDAY)

% B is abbreviated (JAN..DEC)

% B month's full name (January..December)

% C Date and Time (MON NOV 8 14:12:46 CST 1999)

% D for the first few days (01..31)

% D Date (mm / dd / yy)

% h and% b option

% J a year of the year (001..366)

% M Month (01..12)

% W Day a week (0 represents Sunday)

% W Year's first week (00..53, Monday first day)

% x Display Date format (mm / dd / yy)

The last two numbers of% y year (1999 is 99)

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

Note: Only the super user has permission to use the Date command to set the time, the general user can only display the time using the Date command.

Ø Display date and time

Under the character interface, in addition to the annual month, the user can also use the "date" command to display and set the system date and time. It is important to specify that only super users can set the time with the "date" command, and the general user can only display the time with the "date" command.

Display time with the specified format, the command is as follows:

# Date ' The Date of Today IS:% x, IT IS: 00' '' The Date of Today IS:

14/04/04

IT IS: 10: 33: 01 where% x Display Date Format (MM / DD / YY),% X Display Time Format (% H:% M:% S).

Other parameters can look at the settings of the DATE time domain above.

Ø Setting time is 9:16 am

The command is as follows:

# Date -s 09:16:00

Ø Set time is

year 2004

April

14th

The command is as follows:

# Date -s 991128

Where -S is the parameter setting date.

In addition, the "date" command has many useful parameters, which can help users set and display time as they want, such as% h display hour (00..................5),% P display Out of AM or PM,% S display second (00..59) and% z display time zone, etc. Corringly happen, often uses these command parameters, I believe there will be more exciting waiting for everyone.

转载请注明原文地址:https://www.9cbs.com/read-45913.html

New Post(0)