fix: 安卓环境Go Time 固定UTC时区,通过时区获取偏移量修正时区 (#1284)

* fix: 安卓环境Go Time 固定UTC时区,通过时区获取偏移量修正时区

* fix: 去除tZ参数,只有安卓环境情况下根据getprop persist.sys.timezone 修正时区

---------

Co-authored-by: luo.pengcheng <luo.pengcheng@ikasinfo.com>
This commit is contained in:
luopc
2024-10-17 18:25:24 +08:00
committed by GitHub
parent e99ab31f9a
commit 2c4d8a82f8
2 changed files with 25 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"time"
@ -75,6 +76,11 @@ func main() {
update.Self(version)
return
}
// 安卓 go/src/time/zoneinfo_android.go 固定localLoc 为 UTC
if runtime.GOOS == "android" {
util.FixTimezone()
}
// 检查监听地址
if _, err := net.ResolveTCPAddr("tcp", *listen); err != nil {
log.Fatalf("Parse listen address failed! Exception: %s", err)

19
util/andriod_time.go Normal file
View File

@ -0,0 +1,19 @@
package util
import (
"os/exec"
"strings"
"time"
)
func FixTimezone() {
out, err := exec.Command("/system/bin/getprop", "persist.sys.timezone").Output()
if err != nil {
return
}
timeZone, err := time.LoadLocation(strings.TrimSpace(string(out)))
if err != nil {
return
}
time.Local = timeZone
}