Bash date/time arithmetic

我与影子孤独终老i 提交于 2019-12-04 05:27:38

Found out how.

echo "The computer will be suspended at" $(date --date "now $1 minutes")

On BSD-derived systems, you'd use

date -r $(( $(date "+%s") + $1 * 60 ))

i.e. get the current date in seconds, add the number of minutes, and feed it back to date.
Yeah, it's slightly less elegant.

Chris

on linux

SECS=`date "+$s"`
SECS=$(( SECS + $1 * 60 ))
date --date $SECS
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!