How to obtain the time of yesterday or tomorrow in Centos

Source: Internet
Author: User
The date command can get the current time. man shows that many parameters of date can be used, which is easy to format. for example: date + "% F" output format: 2011-12-31date + "% F % H: % M: % S" output format: 2011-12-3116: 29: 50. the current time of the system is printed, if you want to obtain a time relative to the current time, you can use the-d parameter. Example: date-d "tomorrow"

The date command can get the current time. man shows that many parameters of date can be used, which is easy to format. for example:

Date + "% F" output format: 2011-12-31date + "% F % H: % M: % S" output format: 2011-12-31 16:29:50

This is to print the current time of the system. if you want to obtain a time relative to the current time, you can use the-d parameter. For example:

Date-d "tomorrow" + "% F % H: % M: % S" output date-d "yesterday" + "% F % H: % M: % S "output the time at this time yesterday

If I want to get the time of 13 days ago, the-d parameter has more flexible usage, for example:

Date-d "-1 day ago" + "% F % H: % M: % S "output date-d" 1 day ago "+" % F % H: % M: % S "output date-d" 1 week ago "+" % F % H: % M: % S "output time seven days ago, equivalent to date-d "7 day ago" + "% F % H: % M: % S"

We can see that ago is powerful. The first number can be a negative number, and the negative number indicates the future time. the positive number indicates the past time, the second parameter is minute, hour, day, month, and week.


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.