在使用linux命令"date"时添加一些特定时间. [英] Add some specific time while using the linux command "date"

查看:54
本文介绍了在使用linux命令"date"时添加一些特定时间.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux中,date可以帮助我打印当前时间.如果要打印当前时间+ 1小时,我应该选择什么?

In linux, date can help me to print the current time. If want to print the current time + 1 hour, what option should I give?

推荐答案

在Linux上

只需使用-d(或--date)对日期进行一些数学运算即可:

On Linux

Just use -d (or --date) to do some math with the dates:

date -d '+1 hour' '+%F %T'
#    ^^^^^^^^^^^^

例如:

$ date '+%F %T'
2013-04-22 10:57:24
$ date -d '+1 hour' '+%F %T'
2013-04-22 11:57:24
#           ^

在Mac OS上

警告,以上内容仅适用于Linux,不适用于Mac OS.

On Mac OS

Warning, the above only works on Linux, not on Mac OS.

在Mac OS上,等效命令为

On Mac OS, the equivalent command is

date -v+1H

这篇关于在使用linux命令"date"时添加一些特定时间.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆