从unix shell脚本中的日期减去1小时 [英] subtract 1 hour from date in unix shell script

查看:410
本文介绍了从unix shell脚本中的日期减去1小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在shell脚本中有以下内容。如何在保留格式的同时减去一小时?

I have the following in a shell script. How can I subtract one hour while retaining the formatting?

DATE=`date "+%m/%d/%Y -%H:%M:%S"`


推荐答案

以下命令适用于最新版本的GNU date

The following command works on recent versions of GNU date:

date -d '1 hour ago' "+%m/%d/%Y -%H:%M:%S"

这篇关于从unix shell脚本中的日期减去1小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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