The content comes from BBS, which has been sorted out and shared!
Calculate the date 3 days ago
date +%D -d ‘-3 days‘11/03/12
Calculate the date after 3 days
date +%D -d ‘+3 days‘11/09/12
The date after 3 days is calculated. If you do not write +, the result is the same as the result above.
date +%D -d ‘3 days‘11/09/12
Calculate the date one month ago
date +%F -d ‘-1 month‘2012-10-06
Calculate the date of 1 year ago
date +%F -d ‘-1 year‘2011-11-06
Let's take a look at the related time operations. With the above understanding of date operations, it is not difficult to see this time. Ask translate.google.com.hk ^_^
Get current time
date +%T13:48:25
Get the time 1 hour ago
date +%T -d ‘-1 hours‘12:48:27
Obtain the time 10 minutes ago.
date +%T -d ‘-10 minutes‘13:38:35
Get the time after 3 hours
date +%T -d ‘3 hours‘16:49:08
For processing timestamps, the benchmark for timestamps is 00:00:00, January 1, January 1, 1970. Note that this is the time of the Greenwich Mean Observatory, not Beijing time.
Displays the current timestamp of the system.
date +%s1352183334
Convert a timestamp Back To The Date Format
date -d "@1352183334"Tue Nov 6 14:28:54 CST 2012
See, because the system is the time zone of the East 8 region, so when the time stamp is 0, the system should have been on the morning of January 1, January 1, 1970.
date -d "@0"Thu Jan 1 08:00:00 CST 1970
How to calculate the first n days of an arbitrary date or the last n days?
DAY="20000101"echo $DAY20000101date +%F -d "$DAY 1 day"2000-01-02date +%F -d "$DAY -1 day"1999-12-31
How many days is the difference between two dates, such as November 1, 2012 and May 1, 2010?
d1=$(date +%s -d 20121101)d2=$(date +%s -d 20101101)echo $(((d1-d2)/86400))731
This article from the "lisp O & M path" blog, please be sure to keep this source http://lspgyy.blog.51cto.com/5264172/1543682
Advanced date command usage