Go Cheatsheet - Print time in timezone
1, LoadLocation
2, Call time.In
method
package main
import (
"log"
"time"
)
func main() {
t := time.Now()
loc, err := time.LoadLocation("Asia/Shanghai")
if err != nil {
log.Fatalf("%s\n", err)
}
locTime := t.In(loc)
log.Println(locTime.Format("01/02/2006 15:04:05"))
}
Run it:
08/25/2021 05:59:39