获取昨天的日期在Linux上,DST安全的bash [英] Get yesterday's date in bash on Linux, DST-safe
问题描述
我在Linux上运行,并使用这一呼吁得到昨天的日期的shell脚本YYYY-MM-DD
格式:
I have a shell script that runs on Linux and uses this call to get yesterday's date in YYYY-MM-DD
format:
date -d "1 day ago" '+%Y-%m-%d'
它工作的大部分时间,但是当脚本昨日早上 2013年3月11日0:35 CDT
,它返回跑2013 -03-09
而不是2013年3月10日
。
presumably夏令时间(昨天开始),是难辞其咎的。我猜的方式1天前
实施减去了24小时,并在24小时前 2013年3月11日0:35 CDT
是 2013年3月9日23:35 CST
,而导致的2013年3月9日的结果
。
Presumably daylight saving time (which started yesterday) is to blame. I'm guessing the way "1 day ago"
is implemented it subtracted 24 hours, and 24 hours before 2013-03-11 0:35 CDT
was 2013-03-09 23:35 CST
, which led to the result of "2013-03-09"
.
那么,什么是一个很好的DST安全的方式来获得昨天在bash Linux上的日期?
So what's a good DST-safe way to get yesterday's date in bash on Linux?
推荐答案
我觉得这应该工作,不论多久,当你运行它...
I think this should work, irrespective of how often and when you run it ...
date -d "yesterday 13:00 " '+%Y-%m-%d'
这篇关于获取昨天的日期在Linux上,DST安全的bash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!