Update modify_time.sh

This commit is contained in:
spiritLHLS 2022-12-18 12:47:34 +08:00 committed by GitHub
parent 22265c87a8
commit d6f4e8f585
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -51,9 +51,9 @@ check_os() {
main(){
# 获取当前时间和网络时间
CURRENT_TIME=$(date +%s)
CURRENT_TIME=$(date -u +%s)
NETWORK_TIME=$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)
NETWORK_TIME_SECONDS=$(date -d "$NETWORK_TIME" +%s)
NETWORK_TIME_SECONDS=$(TZ=":UTC" date -d "$NETWORK_TIME" +%s)
# 计算时间差
DIFF=$(($NETWORK_TIME_SECONDS-$CURRENT_TIME))
@ -88,14 +88,22 @@ main(){
fi
}
check_again(){
# 获取当前时间和网络时间
CURRENT_TIME=$(date +%s)
NETWORK_TIME=$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)
NETWORK_TIME_SECONDS=$(date -d "$NETWORK_TIME" +%s)
# 获取当前时区
CURRENT_TZ=$(date +%Z)
# 获取网络时间对应的时区
NETWORK_TZ=$(echo "$NETWORK_TIME" | awk '{print $5}')
# 计算时区差,单位是秒
TZ_DIFF=$((($(date -d "$NETWORK_TZ" +%s)-$(date -d "$CURRENT_TZ" +%s))/3600*3600))
# 计算时间差
DIFF=$(($NETWORK_TIME_SECONDS-$CURRENT_TIME))
DIFF=$(($NETWORK_TIME_SECONDS-$CURRENT_TIME-$TZ_DIFF))
# 判断时间差是否在允许范围内
if [ "$DIFF" -lt 300 ] && [ "$DIFF" -gt -300 ]; then
@ -109,6 +117,7 @@ check_again(){
head
check_os
main