数字时间转标准时间:
数字时间如:20151009163000
标准时间:2015-10-19 16:30:00
a=`head -1 /home/xxx/xxx/bin/.status |awk -F= ‘{print $2}‘|sed -r ‘s/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/\1-\2-\3 \4:\5:\6/‘`
把标准时间转换成秒(据1970-1-1):
date -d "$a" +%s
shell脚本中获取日期:
获取今天的日期:
[[email protected] ~]# date -d "now" +%Y%m%d 20150819 [[email protected] ~]#
获取昨天的日期:
[[email protected] ~]# date -d "1 day ago" +%Y%m%d 20150818 [[email protected] ~]# date -d "yesterday" +%Y%m%d 20150818 [[email protected] ~]# date -d "-1 days" +%Y%m%d 20150818 [[email protected] ~]#
获取前天的日期:
[[email protected] ~]# date -d "2 day ago" +%Y%m%d 20150817 [[email protected] ~]# date -d "-2 days" +%Y%m%d 20150817 [[email protected] ~]#
获取上前天的日期:
[[email protected] ~]# date -d "3 day ago" +%Y%m%d 20150816 [[email protected] ~]# date -d "-3 days" +%Y%m%d 20150816 [[email protected] ~]#
获取明天的日期:
[[email protected] ~]# date -d "tomorrow" +%Y%m%d 20150820 [[email protected] ~]# date -d "next-day" +%Y%m%d 20150820 [[email protected] ~]# date -d "day" +%Y%m%d 20150820 [[email protected] ~]# date -d "+1 days" +%Y%m%d 20150820 [[email protected] ~]#
获取两天后的日期:
[[email protected] ~]# date -d "2 day" +%Y%m%d 20150821 [[email protected] ~]# date -d "+2 days" +%Y%m%d 20150821 [[email protected] ~]#
获取三天后的日期:
[[email protected] ~]# date -d "3 day" +%Y%m%d 20150822 [[email protected] ~]# date -d "+3 days" +%Y%m%d 20150822 [[email protected] ~]#
获取一月后的日期:
[[email protected] ~]# date -d "next-month" +%Y%m%d 20150919 [[email protected] ~]# date -d "month" +%Y%m%d 20150919 [[email protected] ~]#
获取一月后第二天的日期:
[[email protected] ~]# date -d "month 2 day" +%Y%m%d 20150919 [[email protected] ~]#
获取一月前的日期:
[[email protected] ~]# date -d "last-month" +%Y%m%d 20150719 [[email protected] ~]#
获取一年前的日期:
[[email protected] ~]# date -d "last-year" +%Y%m%d 20140819 [[email protected] ~]# date -d "-1 year" +%Y%m%d 20140819 [[email protected] ~]#
获取一年前的前一天日期:
[[email protected] ~]# date -d "-1 year -1 days" +%Y%m%d 20140818 [[email protected] ~]#
获取一年后的日期:
[[email protected] ~]# date -d "next-year" +%Y%m%d 20160819 [[email protected] ~]# date -d "year" +%Y%m%d 20160819 [[email protected] ~]# date -d "+1 year" +%Y%m%d 20160819 [[email protected] ~]#
获取一年后的后两天的日期:
[[email protected] ~]# date -d "year 2 day" +%Y%m%d 20160821 [[email protected] ~]#
获取一周前的日期:
[[email protected] ~]# date -d "-1 weeks" +%Y%m%d 20150812 [[email protected] ~]#
获取一周前的前一天日期:
[[email protected] ~]# date -d "-1 weeks -1 days" +%Y%m%d 20150811 [[email protected] ~]#
获取一周前的后一天日期:
[[email protected] ~]# date -d "-1 weeks +1 days" +%Y%m%d 20150813 [[email protected] ~]#
获取一周后的日期:
[[email protected] ~]# date -d "weeks" +%Y%m%d 20150826 [[email protected] ~]#
获取一周后第二天的日期:
[[email protected] ~]# date -d "week day" +%Y%m%d 20150827 [[email protected] ~]#
获取一周后第三天的日期:
[[email protected] ~]# date -d "week 2 day" +%Y%m%d 20150828 [[email protected] ~]#
时间: 2024-10-13 04:42:10