in recent times, when dealing with shell scripts, you have encountered time processing problems. The addition and subtraction of time, as well as the calculation of the difference. Gets the current time stampDate+%s1. The time-plus-minus approach here is to turn the base time into a timestamp, and then, to increase or change the time, into seconds. such as:1990- on- on on: on: onplus 1 hours and 20 minutes processing method: A. Convert the base time to timestamp time1=$(Date+%s-d'1990-01-01 01:01:01')Echo$time 1631126861Timestamp B. Add time to seconds [email protected]~]# time2=$ ((1* -* -+ -* -)) [[email protected]~]#Echo$time 24800C. Two time add, calculate the result time time1=$ (($time 1+$time 2)) Time1=$(Date+%y-%m-%d\%h:%m:%s-d"1970-01-01 UTC $time 1 seconds");Echo$time 11990- on- on Geneva: +: on 2. The time difference calculation method is as follows: .- on- onAnd the- on- on One: One: OneTime difference principle: the same turns into timestamps, then calculates days, hours, minutes, seconds time1=$(($(Date+%s-d'2010-01-01') - $(Date+%s-d'2009-01-01 11:11:11')));EchoTime1 will time1/ -seconds, it becomes a division. Additional instructions: Shell parentheses operation symbol: a=$(Date) equal to: a=`Date'; double parenthesis Operator: a=$((1+2));Echo$a; equal to: a=`Expr 1+2`
Linux shell date and time difference calculation method