Linux shell date and time difference calculation method

Source: Internet
Author: User
Tags add time

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.