在 Linux 中将 x 秒添加到当前日期 [英] Add x seconds to the current date in Linux
问题描述
我这里有两台 Linux (CentOS 6.0) 机器,我需要在当前日期时间上添加(或删除)5 秒.最后,我的两台机器都会有 5 秒的间隔(一台时间正确,另一台多或少 5 秒).
I have two Linux (CentOS 6.0) machines over here and I need to add (or remove) 5 seconds to the current date time. In the end, both my machines would have a gap of 5 seconds (one with the right time and the other one with 5 seconds more or less).
我知道我可以使用以下命令更改日期:
I know I can change the date with this command:
date -s "DD MMM YYYY HH:MM:SS"
但我需要精确,我很难在正确的时间运行命令.
but I need to be precise and it will be hard for me to run the command at the right time.
所以我想知道一般情况下是否有一种方法可以将当前时间增加 5 秒,这有点像您选择时区而不是格林威治(在我的情况下是 +5 小时).
So I'd like to know if there is a way in general to add 5 seconds to the current time, a bit like when you choose your time zone compared to Greenwich (+5 hours in my case).
推荐答案
您可以使用 date -s "5 seconds"
在一个命令中将当前时间增加 5 秒.
You can add 5 seconds to the current time in one command using date -s "5 seconds"
.
关于所有 GNU coreutils 接受的所有日期输入格式的完整手册可以在线找到 https://www.gnu.org/software/coreutils/manual/html_node/Date-input-formats.html.
The full manual regarding all of the date input formats that all of GNU coreutils accepts can be found online at https://www.gnu.org/software/coreutils/manual/html_node/Date-input-formats.html.
这篇关于在 Linux 中将 x 秒添加到当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!