diff --git a/main.go b/main.go index 22ccec3ff..b3fde96a6 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/util/andriod_time.go b/util/andriod_time.go new file mode 100644 index 000000000..1e0144ec1 --- /dev/null +++ b/util/andriod_time.go @@ -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 +}