#!/bin/Bash#declare D="2016-05-06 00:00:00"#d1=$(Date-D"$d"+%s);Echo$d 1#d2=$(Date+%y%m%d%h%m%s-d @ $d 1) #Echo$d * Current time month day #declare Currentsecond=$(Date+%y%m%d%h%m%S) #declare currentminute #当前时间 month and day=$(Date+%y%m%d%h%M) #declare currenthour #当前时间 month and day=$(Date+%y%m%d%H) #当前时间 days #declare currentday=$(Date+%y%m%d) Declare Currenthourofsecond=$(Date+%s) declare Currenthour=$(Date+%y%m%d%h-d @ $currentHourOfSecond) #[the operator to add a space]declare the front and back variables when doing the operation Beforeonehourofsecond=`Expr$currentHourOfSecond-3600' Declare beforeonehour=$(Date+%y%m%d%h-d @ $beforeOneHourOfSecond) declare Beforetwohourofsecond=`Expr$currentHourOfSecond-7200' Declare beforetwohour=$(Date+%y%m%d%h-d @ $beforeTwoHourOfSecond)Echo "Beforeonehour:"$beforeOneHourEcho "Beforetwohour:"$beforeTwoHour # Get the first one hours #declare beforeonehour=$(Date+%y%m%d%h-d'-1 hours') #获取前两个小时时间 #declare beforetwohour=$(Date+%y%m%d%h-d'-2 hours')#Echo "Currentsecond:"$currentSecond #Echo "Currentminute:"$currentMinute #Echo "Currenthour:"$currentHour #Echo "Currentday:"$currentDay #Echo "Beforeonehour:"$beforeOneHour #Echo "Beforetwohour:"$beforeTwoHour
Shell date format and numeric operations