Linux Centos Date Usage experience

Source: Internet
Author: User
Tags locale set time

The Linux time format largely follows the human habit, and the following are some common times.

The date command itself provides the addition and subtraction of dates, which are used flexibly in shell programming.

Common time:

Monday (Mon) Monday

Tuesday (Tue) Tuesday

Wedesday (Wed) Wednesday

Thursday (Thu) Thursday

Friday (Fri) Friday

Saturday (Sat) Saturday

Sunday (Sun) Sunday

Tomorrow tomorrow

Yesterday yesterday

Today

January (Jan) January

February (Feb) February

March (Mar) March

April (APR). April

May May

June (June) June

July (Jul) July

August (August)

September (SEP) September

October (OCT) October

November (Nov) November

December (DEC) December

Year/next year

Last year

1 year agon years ago

1 day ago N days ago

1 month agon months ago

Last month

Month/next Month

1, display the current time, format: 2016-06-18 10:20:30

Use the command: Date command format:

Date [OPTION] ... [+format]

The options to use

%F Full date; Same as%y-%m-%d "display format is year-month-day"

%T time; Same as%h:%m:%s "display format: minutes: Seconds"

%Y Year "display format is years"

%m Month (01..12) "Display format for 01-December"

%d day of month (e.g, 01) "Display format is monthly"

%H Hour (00..23) "when displayed in 24-hour format"

%M minute (00..59) "Show Minutes"

%s second (00..60) "Show seconds"

Method 1:

#Date "+%f%T"

2017-11-08 19:23:41

Method 2:

#Date "+%y-%m-%d%h:%m:%s"

2017-11-08 19:25:46

Method 3:

#Date +%f ""%T

2017-11-08 19:31:23

2. Show the day before yesterday

Use command: Date

Date [OPTION] ... [+format]

%a Locale ' s abbreviated weekday name (e.g., Sun) "Show short form of Week"

%A locale ' s full weekday name (e.g., Sunday) "Show Complete Week"

Method 1:

#date-d "2 days ago" +%a

Monday

#date-d "2 days ago" +%a

Mon

Method 2:

#date-d "Nov 6" +%a

Mon

#date-d "Nov 6" +%a

Monday

#date-d "6 Nov" +%a

Monday

Method 3:

#date-d "20171106" +%a

Mon

#date-d "20171106" +%a

Monday

Method 4:

#Date-d "-2 Day" +%a

Monday

Extended Thinking

2 days ago

#Date-d "-2 Day" +%f

2017-11-10

After January

#date-d "1 month" +%f

2017-12-09

1 weeks later

#date-d "1 weeks" +%f

2017-11-16

1 years ago

#Date-d "-1 year" +%f

2016-11-09

The date of the next Sunday (note: Only positive back weeks, not forward)

#date-d "1 Sun" +%f

2017-11-12

1 minutes ago

#Date-d "-1 min" +%r

09:06

After 5 hours

#Date-d "5 Hour" +%r

14:14

Yesterday is the day of the week:

#date-d "Yesterday" +%a

Wednesday

3, set the current date is 2019-08-07 06:05:10 ( after the display format for convenience verification only )

Use command: Date

Date [-u|--utc|--universal] [MMDDHHMM[[CC]YY][.SS]]

Method 1:

#Date 080706052019.10

Wed 7 06:05:10 CST 2019

Method 2:

#Date-s "08/07/2019 06:05:10"

Wed 7 06:05:10 CST 2019

Method 3:

#Date-s "7 2019 06:05:10" +%f-%r

2019-08-07-06:05:10 AM

Method 4:

#Date-s "2019-08-07 06:05:10" +%f "Time:"%r

2019-08-07 time:06:05:10 AM

Method 5:

#Date-s "20190807 06:05:10" +%f "Time:"%r

Wed 7 06:05:10 CST 2019

Extended Thinking ( The following display format is for easy verification only )

Set time, only root privileges can be set, others can only view

Set the date and time will change to 00:00:00

#Date-s "20190807" +%f "Time:"%T

2019-08-07 time:00:00:00

Set the time only, do not change the date

#Date-s "14:20:15" +%f "Time:"%T

2019-08-07 time:14:20:15



This article is from the "Golden Mystery" blog, please be sure to keep this source http://191226139.blog.51cto.com/211244/1981391

Linux Centos Date Usage experience

Related Article

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.