通过设置本地全局设置时区

Related to Setting timezone globally in golang

In zoneinfo.go you can find the following

// Local represents the system's local time zone.
var Local *Location = &localLoc

wich suggest that you have a global modifiable Local, and you can set it. By setting it, should it have effect to timezones?

Setting time.Local does have an effect on the time local time zone.

For example,

package main

import (
    "fmt"
    "time"
)

func main() {
    now := time.Now().Round(0)
    fmt.Println(now, time.Local)

    loc, err := time.LoadLocation("America/Atka")
    if err != nil {
        fmt.Println(err)
        return
    }
    time.Local = loc

    now = time.Now().Round(0)
    fmt.Println(now, time.Local)
}

Output:

2019-07-16 10:45:41.263418395 -0400 EDT Local
2019-07-16 05:45:41.263530699 -0900 HDT America/Atka

Playground: https://play.golang.org/p/XBxO2toH-SJ