Get the date (a day before current time) in Bash

后端 未结 17 2154
臣服心动
臣服心动 2020-11-30 17:54

How can I print the date which is a day before current time in Bash?

17条回答
  •  误落风尘
    2020-11-30 18:10

    If you have BSD (OSX) date you can do it like this:

    date -j -v-1d
    Wed Dec 14 15:34:14 CET 2011
    

    Or if you want to do date calculations on an arbitrary date:

    date -j -v-1d -f "%Y-%m-%d" "2011-09-01" "+%Y-%m-%d"
    2011-08-31
    

提交回复
热议问题