Digital time Transfer Standard Time:
Digital time such as: 20151009163000
Standard Time: 2015-10-19-16:30:00
A= ' head-1/home/xxx/xxx/bin/.status |awk-f= ' {print $ {} ' |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/"
Convert standard Time to seconds (according to 1970-1-1):
Date-d "$a" +%s
Get date in shell script:
Get today's Date:
[Email protected] ~]# date-d "Now" +%y%m%d20150819[[email protected] ~]#
Get Yesterday's date:
[[email protected] ~]# date-d "1 day Ago" +%y%m%d20150818[[email protected] ~]# date-d "Yesterday" +%y%m%d20150818[[emai L protected] ~]# date-d "-1 days" +%y%m%d20150818[[email protected] ~]#
Get the date of the day before:
[[email protected] ~]# date-d "2 day Ago" +%y%m%d20150817[[email protected] ~]# date-d "-2 Days" +%y%m%d20150817[[email Protected] ~]#
Get the date of the forward day:
[[email protected] ~]# date-d "3 day Ago" +%y%m%d20150816[[email protected] ~]# date-d "-3 days" +%y%m%d20150816[[email Protected] ~]#
Get Tomorrow's Date:
[Email protected] ~]# date-d "Tomorrow" +%y%m%d20150820[[email protected] ~]# date-d "Next-day" +%y%m%d20150820[[email Protected] ~]# date-d "Day" +%y%m%d20150820[[email protected] ~]# date-d "+1 days" +%y%m%d20150820[[email protected] ~]#
Get the date after two days:
[[email protected] ~]# date-d "2 Day" +%y%m%d20150821[[email protected] ~]# date-d "+2 days" +%y%m%d20150821[[email prot Ected] ~]#
Get the date after three days:
[[email protected] ~]# date-d "3 day" +%y%m%d20150822[[email protected] ~]# date-d "+3 days" +%y%m%d20150822[[email prot Ected] ~]#
Get date after January:
[[email protected] ~]# date-d "Next-month" +%y%m%d20150919[[email protected] ~]# date-d "month" +%y%m%d20150919[[email p Rotected] ~]#
Get the date of the second day after January:
[Email protected] ~]# date-d "Month 2 Day" +%y%m%d20150919[[email protected] ~]#
Get the date before the month:
[Email protected] ~]# date-d "Last-month" +%y%m%d20150719[[email protected] ~]#
Get the date one year ago:
[Email protected] ~]# date-d "last-year" +%y%m%d20140819[[email protected] ~]# date-d "-1 year" +%y%m%d20140819[[email Protected] ~]#
Get the day before the year before:
[[email protected] ~]# date-d "-1 year-1 Days" +%y%m%d20140818[[email protected] ~]#
Get the date one year later:
[[email protected] ~]# date-d "next-year" +%y%m%d20160819[[email protected] ~]# date-d "year" +%y%m%d20160819[[email Pro Tected] ~]# date-d "+1 Year" +%y%m%d20160819[[email protected] ~]#
Get the date of the next two days after one year:
[[email protected] ~]# date-d "Year 2 Day" +%y%m%d20160821[[email protected] ~]#
Get the date a week ago:
[[email protected] ~]# date-d "-1 weeks" +%y%m%d20150812[[email protected] ~]#
Get the day before the week before:
[[email protected] ~]# date-d "-1 weeks-1 Days" +%y%m%d20150811[[email protected] ~]#
Get the date of the following day a week ago:
[[email protected] ~]# date-d "-1 weeks +1 days" +%y%m%d20150813[[email protected] ~]#
Get the date after one week:
[Email protected] ~]# date-d "weeks" +%y%m%d20150826[[email protected] ~]#
Get the date of the next day after the week:
[Email protected] ~]# date-d "Week Day" +%y%m%d20150827[[email protected] ~]#
Get the date of the third day after one week:
[[email protected] ~]# date-d "Week 2 Day" +%y%m%d20150828[[email protected] ~]#
This article is from the "Pengcheng-soy sauce bottle" blog, please be sure to keep this source http://yfshare.blog.51cto.com/8611708/1702515
Get date in shell script