mirror of
https://github.com/jeessy2/ddns-go.git
synced 2025-10-20 15:33:46 +08:00
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:
6
main.go
6
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)
|
||||
|
19
util/andriod_time.go
Normal file
19
util/andriod_time.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user