Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use date command to set time in linux

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to use the date command to set time in linux, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Date command

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

The general format of the command is: date [option] display time format (begins with +, followed by format)

Date sets the 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 sets the date described by datestr

-u,-- universal displays or sets universal time

Time domain

The code is as follows:

% H hours (00.23)

% I hours (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 seconds experienced since 00:00:00 on January 1, 1970

% s seconds (00.59)

% T time (24-hour) (hh:mm:ss)

Format of X display time (H:%M:%S)

% Z time zone date field

% an abbreviation of day of the week (Sun..Sat)

The full name of% A day of the week (Sunday..Saturday)

Abbreviation for% b month (Jan..Dec)

Full name of% B month (January..December)

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

% d the day ordinal of a month (01.. 31)

% D date (mm/dd/yy)

H and b options are the same

% j the day ordinal of a year (001. 366)

% m month (01.. 12)

% w the day of the week (0 represents Sunday)

% W the week ordinal of the year (00.53, Monday is the first day)

% x format of display date (mm/dd/yy)

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

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

Note: only superusers have permission to use the date command to set the time, and ordinary users can only use the date command to display the time.

Show date and time

In the character interface, in addition to displaying the year and month, the user can also use the "date" command to display and set the system date and time. It should be noted that only superusers can set the time with the "date" command, and the average user can only use the "date" command to display the time.

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

Where x displays the format of the date (mm/dd/yy) and X shows the format of the time (H:%M:%S).

For other parameters, you can see the settings of the date time domain above.

Example:

Code example:

Set the time to 09:16

The command is as follows:

# date-s 09:16:00

The setting time is August 1, 2013.

The command is as follows:

# date-s 130801

Where-s is the parameter that sets the date.

The setting time is 09:16 on August 1, 2013.

The command 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 will not give detailed examples, such as% H display hours (00.23),% M display minutes (00.59),% p display AM or PM,% S display seconds (00.59) and% Z display time zone, etc.

You can study it on your own.

The above is how to use the date command to set the time in linux. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 284

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report