````
import (
"fmt"
"time"
)
func main() {
now = time.Now().Unix()
mTmZone := int64(1)
timeFormat := LocalTime(now, mTmZone).Format("2006-01-02 15:04:05")
loc, err := time.LoadLocation("Europe/Malta")
fmt.Println(loc, err)
testz, _ := time.ParseInLocation("2006-01-02 15:04:05", timeFormat, loc)
if (testz.Hour()+24-testz.UTC().Hour())%24 > mTmZone { //这个时候时间正偏移, 带夏令时
diff := (testz.Hour()+24-testz.UTC().Hour())%24 - mTmZone
testz = jojoTime.LocalTime(now+int64(diff*3600), mTmZone)
}
fmt.Println(testz.Format("2006-01-02 15:04:05"))
}
//diff为标准时区
func LocalTime(tm int64, diff int64) time.Time {
//这里固定本机系统时间的时区为 Asia/Shanghai +8区
if tm > 9999999999 {
//毫秒
tm = tm / 1000
}
var locTm int64
if diff == 8 {
locTm = tm
} else if diff < 8 {
locTm = tm - (8-diff)*3600
} else {
locTm = tm + (diff-8)*3600
}
return time.Unix(locTm, 0)
}
````
有疑问加站长微信联系(非本文作者)