Bash脚本/命令在日期之前/之后5分钟打印出日期 [英] Bash script/command to print out date 5 min before/after
本文介绍了Bash脚本/命令在日期之前/之后5分钟打印出日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要以某种方式在bash或其他实用程序中使用date命令来打印日期和时间,即给定值之前5分钟和之后5分钟. 例如:
I need to somehow use the date command in bash or another utility to print out the date and time, 5 minutes before and 5 minutes after a given value. For example:
输入:
Thu Dec 19 14:10
输出:
Thu Dec 19 14:05 Thu Dec 19 14:10 Thu Dec 19 14:15
我看到date
命令可用于在当前日期/时间执行此操作,它是否可以与传递的值(即不是当前日期/时间)一起使用?
I see that the date
command can be used to do this on the current date/time, can it be used with a passed value, i.e. not the current date/time?
推荐答案
您当前可以通过键入来实现.
You can achieve this, for the current time, by typing.
$ date --date='5 minutes ago'; date; date --date='5 minutes'
Qui Dez 19 16:09:17 BRST 2013
Qui Dez 19 16:14:17 BRST 2013
Qui Dez 19 16:19:17 BRST 2013
使用特定日期(例如1978/01/10).
To use a specific date (ex 1978/01/10).
$ date --date='1978-01-10 + 5 minutes'
Ter Jan 10 00:05:00 BRT 1978
这篇关于Bash脚本/命令在日期之前/之后5分钟打印出日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文