In daily work, the bash shell has a very frequent time operation. For example, when the shell script sends statistics periodically, it will check whether the scheduled send time is current. Or when you use a file to save some data, a time string is typically generated as part of the file name. Summing up, later use will not have to surf the internet everywhere.
<1> the most basic operation, get the current time (year-month-day time: minutes: seconds):
Date + "%y-%m-%d%h:%m:%s"
%I Hours, 12-hour system
%s from January 1, 1970 00:00:00 to the number of seconds currently experienced
%a Week's (SUN~SAT)
%b month abbreviation (JAN~DEC)
<2> time before or after the specified interval
3 hours before the time date-d "1 hour" + "%y-%m-%d%h:%m:%s"
3 hours after the time date-d "+1 hour" + "%y-%m-%d%h:%m:%s"
3 days prior to date-d "-1 day" + "%y-%m-%d%h:%m:%s"
Take 3 days after date-d "+1 Day" + "%y-%m-%d%h:%m:%s"
Take 1 months ago date-d "1 month" + "%y-%m-%d%h:%m:%s"
1 months after the time date-d "+1 month" + "%y-%m-%d%h:%m:%s"
Take 1 years ago date-d "1 year" + "%y-%m-%d%h:%m:%s"
1 years after the time date-d "+1 year" + "%y-%m-%d%h:%m:%s"
<3> Timestamp and string conversion
String to timestamp date-d "2018-08-15 21:33:00"-S
Timestamp to String date-d "1970-01-01 UTC 1534337485 seconds" + "%y-%m-%d%h:%m:%s"
<4> time Addition and subtraction
This seems to only turn the string into a timestamp, add and subtract, in the conversion back to the string, I found no simple way.
Summary of common methods for time operations in bash shell