是否可以通过bash将当前时间更改为另一个时间?例如,如果我将当前时间(假设是4:00 pm)作为文件的参数传递,是否可以将3pm传递给文件?
谢谢。
答案 0 :(得分:1)
执行以下操作:
received_time="3:00pm"
date +%I:%M%p -d "$received_time - 1 hour"
来自date --help
:
Usage: date [OPTION]... [+FORMAT]
-d, --date=STRING display time described by STRING, not 'now'
FORMAT controls the output. Interpreted sequences are:
%I hour (01..12)
%M minute (00..59)
%p locale's equivalent of either AM or PM; blank if not known