Shell script to get the formatting Date and Time Summary

Source: Internet
Author: User

Shell script to get the formatting Date and Time Summary

The Shell script obtains the formatting Date and Time summary. The Linux bash script's support for time formats exceeds my expectation and supports changes and outputs in multiple formats. It is even more convenient than java APIs. It is summarized as follows:

#! /Bin/sh # upload logs to hdfssource/etc/profile # obtain yesterday's date in the yyyyMMdd format yesterday = 'date -- date = '1 days ago '+ % Y % m % d '# obtain the format of yesterday's yyyy-MM-dd yesterday2 = 'date -- date = '1 days ago '+ % Y-% m-% d' # obtain today's date in the yyyyMMdd format today =' date -- date = '0 days ago '+ % Y % m % d' # Get today's date in yyyy-MM-dd format today2 = 'date -- date = '0 days ago' + % Y-% m-% d' # get tomorrow's date in yyyyMMdd format today = 'date -- date = '1 days '+ % Y % m % d' # get tomorrow's date in yyyy- MM-dd format today2 = 'date -- date = '1 days' + % Y-% m-% d' # obtain the current time yyyy-MM-dd HH: mm: ss format nowtime = 'date -- date = '0 days ago '"+ % Y-% m-% d % H: % M: % S "'# obtain the current daytime HH: mm: ss format nowtime2 = 'date -- date = '0 days ago' + % H: % M: % s' # obtain the time from yyyy-MM-dd HH: mm: ss format: onehourage = 'date -- date = '1 hours ago '"+ % Y-% m-% d % H: % M: % S "'# obtain yyyy-MM-dd HH: mm: ss format: onehourage2 = 'date -- date = '1 hours' "+ % Y-% m-% d % H: % M: % S "'# obtain yyyy-MM-dd HH: mm: 2 hours ago: ss format: twohourage = 'date -- date = '2 hours ago '"+ % Y-% m-% d % H: % M: % S "'# Get 2 hours later in yyyy-MM-dd HH: mm: ss format: twohourage2 = 'date -- date = '2 hours' "+ % Y-% m-% d % H: % M: % S "'# obtain yyyy-MM-dd HH: mm: 1 month ago: ss format date -- date = '1 month ago '"+ % Y-% m-% d % H: % M: % S "# Get 1 month plus 1 day before yyyy-MM-dd HH: mm: ss format date -- date = '1 month ago + 1 day ago '"+ % Y-% m-% d % H: % M: % S "# Get 1 month minus 1 day before yyyy-MM-dd HH: mm: ss format date -- date = '1 month ago-1 day ago '"+ % Y-% m-% d % H: % M: % S "# Get 1 month plus 1 day plus 1 hour plus 1 minute plus 1 second before the time yyyy-MM-dd HH: mm: ss format date -- date = '1 month ago + 1 day ago + 1 hour ago + 1 min ago + 1 sec ago '"+ % Y-% m-% d % H: % M: % S "# Get 1 month plus 1 day minus 1 hour minus 1 minute minus 1 second before the time yyyy-MM-dd HH: mm: ss format can be +-misuse date -- date = '1 month ago + 1 day ago-1 hour ago-1 min ago-1 sec ago '"+ % Y-% m-% d % H: % M: % S "# Get 1 month plus 1 day plus 1 hour plus 1 minute plus 1 second after the time yyyy-MM-dd HH: mm: ss format date -- date = '1 month + 1 day + 1 hour + 1 min + 1 sec '"+ % Y-% m-% d % H: % M: % S "# Get 1 month plus 1 day minus 1 hour minus 1 minute minus 1 second after the time yyyy-MM-dd HH: mm: ss format date -- date = '1 month + 1 day-1 hour-1 min-1 sec '"+ % Y-% m-% d % H: % M: % S "# Get 1 year after 1 month plus 1 day minus 1 hour minus 1 minute minus 1 second after the time yyyy-MM-dd HH: mm: ss format date -- date = '1 year 1 month + 1 day-1 hour-1 min-1 sec '"+ % Y-% m-% d % H: % M: % S "# Get 1 month a year ago plus 1 day minus 1 hour minus 1 minute minus 1 second after the time yyyy-MM-dd HH: mm: ss format date -- date = '1 year 1 month + 1 day-1 hour-1 min-1 sec '"+ % Y-% m-% d % H: % M: % S"

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.