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 get yesterday or tomorrow time through date command in linux

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

Share

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

This article mainly explains "how to get yesterday or tomorrow time through date command in linux". The explanation in the article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn "how to get yesterday or tomorrow time through date command in linux".

For example:

The code is as follows:

Date + "% F"

Output format: 2011-12-31

Date + "F H:%M:%S"

Output format: 2011-12-31 16:29:50

This is to print out the current time of the system, and if you want to get a certain time relative to the current time, what you need to do, you can do it through the-d parameter. For example:

The code is as follows:

Date-d "tomorrow" + "F H:%M:%S"

Output the time at this time tomorrow

Date-d "yesterday" + "F H:%M:%S"

Output the time at this time yesterday

If I want to get the time 13 days ago, the-d parameter has a more flexible use, such as:

The code is as follows:

Date-d "- 1 day ago" + "F H:%M:%S"

Output the time at this time tomorrow

Date-d "1 day ago" + "F H:%M:%S"

Output the time at this time yesterday

Date-d "1 week ago" + "F H:%M:%S"

Output the time at this time seven days ago, which is equivalent to

Date-d "7 day ago" + "F H:%M:%S"

You can see the power of ago. The first number can be negative, the negative number represents the future time, the positive number represents the past time, and the second parameter minute, hour, day, month, week.

Thank you for your reading, the above is the content of "how to get yesterday or tomorrow time through date command in linux". After the study of this article, I believe you have a deeper understanding of how to get yesterday or tomorrow time through date command in linux, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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: 296

*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