"Intravenous drip" LINUX date command __linux

Source: Internet
Author: User
The date command is very often used, in addition to entering date directly, more often than not, we want to output in a specific format, each time before using the turn of Man or--help, write down to deepen the impression. Arguments to the date command can use the "+" number, which is to facilitate the output of dates in a particular format; use: date [options] [+ format] option:-D,--Date #显示指定字符串的时间而非当前时间
Format:%Y #表示年%m #表示月%d #表示天%H #表示小时 (00-23)%k #表示小时 (0-23)%I (capital I) #表示小时 (01-12)%l (lowercase L) #表示小时 ( 0-12)%m #表示分钟 (00-59)%P #AM/pm%s #表示秒%s #unix时间戳
Example:
#特定格式输出
> Date +%y%m%d
20150527
> Date +%y-%m-%d
2015-05-27
> Date "+%y-%m-%d%h:%m:%s"
2015-05-27 09:41:04
#输出明天
> date-d Tomorrow "+%y-%m-%d"
2015-05-28
#输出昨天
> date-d Yesterday "+%y-%m-%d"
2015-05-26
#输出特定字符串的日期
> date-d "20150424"
Fri Apr 00:00:00 CST 2015< C15/>> date-d "20150424 12:12:12"
Fri Apr 12:12:12 CST 2015
> date-d "2015-04-24"
Fri Apr 24 00: 00:00 CST 2015
#按指定格式输出特定字符串的日期
> date-d "20150424" "+%y-%m-%d"
2015-04-24
#输出指定时间差的日期
> date-d "+1 Day"
Thu could 09:49:47 CST 2015
> date-d "-1 Day" "+%y-%m-%d"
2015-05-26
> D Ate-d "-2 Day" "+%y-%m-%d"
2015-05-25
> date-d "-2 Days" "+%y-%m-%d"
2015-05-25
> date-d "-2 Day "" +%y-%m-%d "
2015-05-25
> date-d"-2 Week "" +%y-%m-%d "
2015-05-13
> date-d"-2 Month "" +% y-%m-%d "
2015-03-27
> date-d"-2 Year "+%y-%m-%d"
2013-05-27


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.