$(TZ = MSZ + 24 date +“%d%m%Y”)在夏令时期间无法正常工作? [英] $(TZ=MSZ+24 date +"%d%m%Y") not working as expected during daylight savings?

查看:213
本文介绍了$(TZ = MSZ + 24 date +“%d%m%Y”)在夏令时期间无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,该脚本利用 $(TZ = MSZ + 24 date +%d%m%Y)来获取昨天的BASH日期(AIX系统)。到目前为止,它已经完美地工作了5个月,直到昨晚它无法正常工作为止。通常,它在服务器时间上午01:00运行,但是昨晚发生了一些奇怪的事情,并且它不起作用的唯一原因是因为 $(TZ = MSZ + 24 date +%d% m%Y)

I have a script that makes use of $(TZ=MSZ+24 date +"%d%m%Y")to get yesterday's date in BASH (AIX system). So far it's worked flawlessly for 5 months, until last night, when it didn't worked properly. Usually it runs at 01:00 AM server time, but last night something strange happened, and the only reason it wouldn't have worked is because of $(TZ=MSZ+24 date +"%d%m%Y").

所以,我的问题是,如果星期六晚上时钟前进1个小时,会影响 $(TZ = MSZ + 24 date + %d%m%Y),所以当它在星期日运行时,它会给出奇怪的结果吗?

So, my question is, if Saturday night the clock went forward 1 hour, could it influence $(TZ=MSZ+24 date +"%d%m%Y") so when it ran on Sunday, it would have given a strange result ?

谢谢

推荐答案

由于夏时制,24几小时前可以是今天或前天。如果要在不使用GNU日期的情况下更改脚本,请使用以下技巧:

Due to the daylight saving time, 24 hours ago can be today or the day before yesterday. When you want to change your script without using the GNU-date, use the following trick:

您确定昨天是20或30小时前。哪一个?好吧,最近的不是今天。

You are sure that yesterday is 20 or 30 hours ago. Which one? Well, the most recent one that is not today.

echo "$(TZ=MSZ+30 date +"%d%m%Y")
$(TZ=MSZ+20 date +"%d%m%Y")" | grep -v "$(date +"%d%m%Y")" | tail -1

这篇关于$(TZ = MSZ + 24 date +“%d%m%Y”)在夏令时期间无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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