整理一些shell获取时间的方法,freebsd与centos会有一些区别
1、获取当前日期前一天
yersterday=$(/bin/date -d-1days "+%Y%m%d") //centos
yersterday=$(/bin/date -v-1d "+%Y%m%d") //freebsd
2、获取当前时间的后一天
yersterday=$(/bin/date -d+1days "+%Y%m%d") //centos
tomorrow=$(/bin/date -v+1d "+%Y%m%d") //freebsd
3、获取给定日期的后一天
tomorrow=$(/bin/date -d"tomorrow $thedate" +%Y%m%d); //centos
4、获取给定时间的前一天
yesterday=$(/bin/date -d"yesterday$thedate" +%Y%m%d); //centos
5、将给定的日志转换成YYYY-MM-DD格式
date=$(/bin/date --date=${thedate} "+%Y-%m-%d"); //centos