Shell date format and numeric operations

Source: Internet
Author: User

#!/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

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.