How to realize time and time Zone conversion in golang
How to achieve time and time zone conversion in golang? aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Package utilsimport ("fmt"time") const LOGTIMEFORMAT = "2006-01-02 15:04:05" func GetTimeStamp () string {t: = time.Now () return fmt.Sprintf ("% D000", t.Unix ())} func GetYMDH () string {t: = time.Now (). UTC () loc Err: = time.LoadLocation ("Asia/Shanghai") if err! = nil {return t.String ()} t = t.In (loc) return fmt.Sprintf ("dddd", t.Year (), t.Month (), t.Day (), t.Hour ())} func utcToZone (t string, zone string) (string, error) {d, err: = time.Parse (LOGTIMEFORMAT T) if err! = nil {return ", err} / / loc, err: = time.LoadLocation (" Local ") loc, err: = time.LoadLocation (zone) if err! = nil {return", err} d = d.In (loc) return d.Format (LOGTIMEFORMAT), nil} func zoneToUTC (t string, zone string) (string, error) {d, err: = time.Parse (LOGTIMEFORMAT+ "MST") T + "" + zone) if err! = nil {return ", err} loc, err: = time.LoadLocation (" UTC ") if err! = nil {return", err} d = d.In (loc) return d.Format (LOGTIMEFORMAT), nil} answers to questions about how to achieve time and time zone conversion in golang are shared here. I hope the above content can help you to a certain extent, if you still have a lot of doubts to be solved, you can follow the industry information channel to learn more related knowledge.