[Shell] get after|before year,month,day,week,hour,minute,second

tolilong發表於2016-04-30
year
[root@oracle ~]# date;date -d "1year"
Tue Mar  8 23:45:18 CST 2016
Wed Mar  8 23:45:18 CST 2017
[root@oracle ~]# date;date -d "-1year"
Tue Mar  8 23:45:25 CST 2016
Sun Mar  8 23:45:25 CST 2015

month
[root@oracle ~]# date;date -d "-1month"
Tue Mar  8 23:46:44 CST 2016
Mon Feb  8 23:46:44 CST 2016
[root@oracle ~]# date;date -d "1month"
Tue Mar  8 23:46:48 CST 2016
Fri Apr  8 23:46:48 CST 2016

day
[root@oracle ~]# date;date -d "1day"
Tue Mar  8 23:47:11 CST 2016
Wed Mar  9 23:47:11 CST 2016
[root@oracle ~]# date;date -d "-1day"
Tue Mar  8 23:47:14 CST 2016
Mon Mar  7 23:47:14 CST 2016

week
[root@oracle ~]# date;date -d "-1week"
Tue Mar  8 23:47:48 CST 2016
Tue Mar  1 23:47:48 CST 2016
[root@oracle ~]# date;date -d "1week"
Tue Mar  8 23:47:52 CST 2016
Tue Mar 15 23:47:52 CST 2016

hour
[root@oracle ~]# date;date -d "1hour"
Tue Mar  8 23:48:06 CST 2016
Wed Mar  9 00:48:06 CST 2016
[root@oracle ~]# date;date -d "-1hour"
Tue Mar  8 23:48:09 CST 2016
Tue Mar  8 22:48:09 CST 2016

minute
[root@oracle ~]# date;date -d "-1min"
Tue Mar  8 23:48:43 CST 2016
Tue Mar  8 23:47:43 CST 2016
[root@oracle ~]# date;date -d "1min"
Tue Mar  8 23:48:46 CST 2016
Tue Mar  8 23:49:46 CST 2016

second
[root@oracle ~]# date;date -d "1second"
Tue Mar  8 23:49:04 CST 2016
Tue Mar  8 23:49:05 CST 2016
[root@oracle ~]# date;date -d "-1second"
Tue Mar  8 23:49:08 CST 2016
Tue Mar  8 23:49:07 CST 2016

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-2091347/,如需轉載,請註明出處,否則將追究法律責任。

相關文章