$(TZ=MSZ+24 date +“%d%m%Y”) not working as expected during daylight savings?

混江龙づ霸主 提交于 2019-12-13 08:34:52

问题


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").

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 ?

Thank you


回答1:


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:

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


来源:https://stackoverflow.com/questions/36257678/tz-msz24-date-dmy-not-working-as-expected-during-daylight-savings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!