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:
Copy codeThe 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 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:
Copy codeThe 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 of 13 days ago, the-d parameter has more flexible usage, for example:
Copy codeThe 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 seven days ago, which is equivalent
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.