问题
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