我正在尝试查找今天前7天的日期.
I am trying to find the date that was seven days before today.
CURRENT_DT=`date +"%F %T"` diff=$CURRENT_DT-7 echo $diff我正在尝试类似上述的方法,以查找比当前日期少7天的时间.有人可以帮我吗?
I am trying stuff like the above to find the 7 days less than from current date. Could anyone help me out please?
推荐答案GNU date将为您提供数学帮助:
GNU date will to the math for you:
date --date "7 days ago"其他版本将要求您从UNIX时代开始就将当前日期转换为秒,手动减去7天的秒数,然后将其转换回所需的形式.请查阅您的date版本的文档,以获取有关如何在Unix时间戳之间进行转换的详细信息.这是再次使用GNU date的示例:
Other version will require you to covert the current date into seconds since the UNIX epoch first, manually subtract 7 days' worth of seconds, and convert that back into the desired form. Consult the documentation for your version of date for details on how to convert to and from Unix timestamps. Here's an example using GNU date again:
x=$(date +%s) x=$((x - 7 * 24 * 60 * 60)) date --date @$x更多推荐
如何在Unix中找到当前日期减去7天?
发布评论