Using the shell to turn the time string and time stamp to each other

Source: Internet
Author: User

The detailed user of date can refer to the following

Http://www.cnblogs.com/xd502djj/archive/2010/12/29/1919478.html

The specific use of date can be viewed in another post, "Shell Date command Detail" http://blog.csdn.net/runming918/article/details/7223520

Date +%s can get Unix timestamp;
Use the shell to turn the time string with the timestamp:
Date-d "2010-10-18 00:00:00" +%s output shape: 1287331200
And the time stamp is converted to a string to do this:
date-d @1287331200 "+%y-%m-%d" Output form: 2010-10-18
If you need to get the days before and after the specified date, you can:
1, seconds= ' date-d "2010-10-18 00:00:00" +%s ' #得到时间戳
2. seconds_new= ' expr $seconds + 86400 ' #加上一天的秒数86400
3, date_new= ' date-d @ $seconds _new "+%y-%m-%d" ' #获得指定日前加上一天的日前

Using the shell to turn the time string and time stamp to each other

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.