BASH SHELL中能夠定義變量顯示當前日期html
顯示當前日期是git
DATE=`date +%Y%m%d` +號後面是定義格式爲年月日ide
顯示前一天爲ui
DATE1=`date -d '1 days ago' +%Y%m%d` 加-d參數能夠設置與當前日期的計算時間,一樣,前2天爲'2 days ago',去掉ago則爲當前日期以後多少天this
如下內容就是網上看到的一篇不錯的文章,出自http://www.labri.fr/perso/strandh/Teaching/USI/Common/Sh-utils/sh-utils_65.htmlidea
Here are a few examples. Also see the documentation for the `-d' option in the previous section.code
date --date='2 days ago'
date --date='3 months 1 day'
date --date='25 Dec' +%j
date '+%B %d'But this may not be what you want because for the first nine days of the month, the `%d' expands to a zero-padded two-digit field, for example `date -d 1may '+%B %d'' will print `May 01'.
-
modifier to suppress the padding altogether. date -d=1may '+%B %-d'
date
when setting the system clock: date +%m%d%H%M%Y.%S
date --set='+2 minutes'
Mon, 25 Mar 1996 23:34:17 -0600
date --date='1970-01-01 00:00:01 UTC +5 hours' +%s 18001Suppose you had not specified time zone information in the example above. Then, date would have used your computer's idea of the time zone when interpreting the string. Here's what you would get if you were in Greenwich, England:
# local time zone used date --date='1970-01-01 00:00:01' +%s 1
date --date='2000-01-01 UTC' +%s 946684800To convert such an unwieldy number of seconds back to a more readable form, use a command like this:
date -d '1970-01-01 946684800 sec' +"%Y-%m-%d %T %z" 2000-01-01 00:00:00 +0000