Shell Date Command Detailed

Source: Internet
Author: User

  Format: Date [options] ... [+ format]

Option Description:

-D,--date= string displays the time described by the specified string

Format Description:

Example 1:

#!/bin/bash##1. Gets the current system time yyyy-mm-DD HH:MM:SSv_time_eq=`Date "+%f%T"' V_time=`Date "+%y-%m-%d%h:%m:%s"`        Echo-E"System Current Time v_time: ${v_time}, V_time_eq: ${v_time_eq} \tv_time is equivalent to v_time_eq, but v_time format, more readable, recommended to use. "##2. Gets the date of the specified format yyyy-mm-dd, YYYYMMDD, yyyy/mm/ddv_date=`Date-D"$v _time"+%y%m%d ' V_date_dir=`Date-D"$v _time"+%y/%m/%d ' V_date_hor=`Date-D"$v _time"+%y-%m-%d 'Echo "System Current date v_date: ${v_date}, V_date_dir: ${v_date_dir}, V_date_hor: ${v_date_hor}. Feel the different formats. "##3. Gets the date of the day before, Yyyymmddv_date_ago_1=`Date-D"$v _date-1 Day"+%y%m%d ' V_date_future_1=`Date-D"$v _date 1 Day"+%y%m%d 'Echo "the day before V_date_ago_1: ${v_date_ago_1}, V_date_future_1: ${v_date_future_1}"##4get the date of the first one months and the last one months Yyyymmddv_date_ago_1month=`Date-D"$v _date-1 Month"+%y%m%d ' #遇到2月闰月的时候, there will be problems, such as 20170329, the first one months will become 20170301v_date_ago_1month_leap=`Date-D"20170329-1 Month"+%y%m%d ' V_date_future_1month=`Date-D"$v _date 1 month"+%y%m%d 'Echo "previous one month date V_date_ago_1month: ${v_date_ago_1month}, last one month date v_date_future_1month: ${v_date_future_1month}"        Echo "Leap February, there will be problems, such as 20170329 of the first one months returned is: ${v_date_ago_1month_leap}, not 20170228"##5. Gets the date of the previous year, the following year Yyyymmddv_date_ago_1year=`Date-D"$v _date-1 Year"+%y%m%d ' V_date_future_1year=`Date-D"$v _date 1 year"+%y%m%d 'Echo "date of previous year V_date_ago_1year:${v_date_ago_1year}, date of the following year V_date_future_1year: ${v_date_future_1year}"##6. Get the system current month month date Yyyymmddv_month=`Date-D"$v _date"+%y%m ' onV_month_ago_1=`Date-D"$v _month-1 Month"+%y%m ' onV_month_future_1=`Date-D"$v _month 1 month"+%y%m ' on        Echo "system Current Month early Month date V_month:${v_month}, early last month date V_month_ago_1:${v_month_ago_1}, early next month date V_month_future_1:${v_month_ Future_1}"
View Code

Results:

Shell Date Command Detailed

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.