繁华开满天机
使用时间。解析In位置,用于在没有给定时区时解析给定位置中的时间。 是您当地的时区,请将其作为您的位置传递。time.Localpackage mainimport ( "fmt" "time")func main() { // This will honor the given time zone. // 2012-07-09 05:02:00 +0000 CEST const formWithZone = "Jan 2, 2006 at 3:04pm (MST)" t, _ := time.ParseInLocation(formWithZone, "Jul 9, 2012 at 5:02am (CEST)", time.Local) fmt.Println(t) // Lacking a time zone, it will use your local time zone. // Mine is PDT: 2012-07-09 05:02:00 -0700 PDT const formWithoutZone = "Jan 2, 2006 at 3:04pm" t, _ = time.ParseInLocation(formWithoutZone, "Jul 9, 2012 at 5:02am", time.Local) fmt.Println(t)}