- How many days until the end of the year | commandlinefu.com
http://www.commandlinefu.com/commands/view/4804/how-many-days-until-the-end-of-the-year
から,今年の残り日数.
echo "There are $(($(date +%j -d"Dec 31, $(date +%Y)")-$(date +%j))) left in year $(date +%Y)." echo "There are $(($(date +%j -d"Dec 31")-$(date +%j))) left in year $(date +%Y)." echo "There are $(($(date +%j -d"Dec 31")-$(date +%-j))) left in year $(date +%Y)."
1 つめの date の引数を目的の日付にすればよい.
%j は年内通算日数を表す日付フィールド
$ date +%j -d"Dec 31 2010" 365 $ date +%j -d"Dec 31 2008" 366
日付フィールドのハイフンはパディングの制御
$ date +%j -d"Feb 08" 039 $ date +%-j -d"Feb 08" 39
- n 日前の日付けを求める [2005-09-30-6]