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

后端 未结 17 2146
臣服心动
臣服心动 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:08

    You could do a simple calculation, pimped with an regex, if the chosen date format is 'YYYYMM':

    echo $(($(date +"%Y%m") - 1)) | sed -e 's/99$/12/'
    

    In January of 2020 it will return 201912 ;-) But, it's only a workaround, when date does not have calculation options and other dateinterpreter options (e.g. using perl) not available ;-)

提交回复
热议问题