In-Shell date operations

Source: Internet
Author: User

1. date-d operation

Date  +"%y%m%d" -D  "+ndays"         #今天的后n天日期   Date  +"%y%m%d" -D  "-ndays"         #今天的前n天日期

2. Common Date format output

Date+"%F"#输出: -- .- ,Date+"%d"#输出: ./ ,/ ADate+"%y%m%d%h:%m:%s"#输出:20120608 Geneva: the: -Date+"%y%m%d"#输出:20120608Date+"%y%m%d%h:%m:%s"-D"+1 hours"#输出:20120608  to: the: +Date+"%y%m%d%h:%m:%s"-D"+1 Days"#输出:20120609 Geneva: the: theDate+"%y%m%d%h:%m:%s"-D"+1 months"#输出:20120708 Geneva: the: AboutDate+"%y%m%d%h:%m:%s"-D"+1 years"#输出:20130608 Geneva: -: -Date+"%T"#输出: to:Geneva: +Date+"%F%T"#输出: -- .- ,  to:Geneva: theDate+"%d%T"#输出: ./ ,/ A  to:Geneva: the

3. Date format Conversion

# string to TimestampDate-D"2010-10-18 00:00:00"+%s #输出:1287331200# Timestamp to StringDate-D @1287331200  "+%y-%m-%d"#输出: .-Ten- -# Gets the last n days of the specified date, if it is the first n days, then the middle of the second part is-Step 1:Get time stampseconds=`Date-D"2010-10-18 00:00:00"+%s '
Step 2:Plus the number of seconds in N days 86400*nseconds_new=`Expr$seconds +86400*n '
Step 3:Get a date plus a day before the specified datedate_new=`Date-D @ $seconds _new"+%y-%m-%d"`

In-Shell date 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.