package models import "time" type User struct { ID int64 Username string PasswordHashed []byte TimeZone string } func (u User) FormatTime(t time.Time) string { if loc := getLocation(u.TimeZone); loc != nil { return t.In(loc).Format("2006-01-02 15:04:05") } return t.Format("2006-01-02 15:04:05") } var loadedLocation = map[string]*time.Location{} func getLocation(tz string) *time.Location { if loc, ok := loadedLocation[tz]; ok { return loc } loc, err := time.LoadLocation(tz) if err != nil { loc = time.Local } loadedLocation[tz] = loc return loc }