go error time: Time.In の呼び出しに場所がありません。解決するエラーを記録するために使用します。
間違った説明
タイムゾーンはGoコードで使用されます
const timezone = "Asia/Shanghai"
func TimeFormat(date time.Time, pattern string) string {
location, err := time.LoadLocation(timezone)
date.In(location)
return date.Format(pattern)
}
現時点では、一部のサーバーとコンピューターは、 Time.In への呼び出しで time.LoadLocation: time: missing Location を使用すると、ファイルまたは構成が欠落しているため、エラーを報告します。
解決
const timezone = "Asia/Shanghai"
func TimeFormat(date time.Time, pattern string) string {
location, err := time.LoadLocation(timezone)
if err != nil {
location = time.FixedZone("CST", 8*3600) //替换上海时区方式
}
date.In(location)
return date.Format(pattern)
}