我寫了一個 golang 程序來生成不同位置的開始日期和結束日期if month != "" && year != "" { var monthInt, _ = strconv.Atoi(month) var yearInt, _ = strconv.Atoi(year) timeZone, err := time.LoadLocation("America/Pheonix") if err != nil { fmt.Println(err)// nil } // currentLocation := time.Now().Location(timeZone) // when I use this it will works // both are of same type fmt.Println(reflect.TypeOf(timeZone)) fmt.Println(reflect.TypeOf(time.UTC)) firstOfMonth := time.Date(yearInt, time.Month(monthInt), 1, 0, 0, 0, 0, timeZone) onlyStartDate := strings.Split(firstOfMonth.Format("2006-01-02 00:00:00 -0000"), " ") lastOfMonth := firstOfMonth.AddDate(0, 1, -1).Format("2006-01-02 00:00:00 -0000") onlyLastDate := strings.Split(lastOfMonth, " ") merchantDb.GetProvidersOfTheMonth(onlyStartDate[0], onlyLastDate[0])}但是當我運行這段代碼時,它會給我以下錯誤:-時間:在調用 Date 時缺少位置為什么會產生此錯誤以及我將如何解決此錯誤?請任何建議!
1 回答

MMMHUHU
TA貢獻1834條經驗 獲得超8個贊
應該是America/Phoenix
,不是America/Pheonix
。
timeZone,?_?:=?time.LoadLocation("America/Phoenix")
- 1 回答
- 0 關注
- 135 瀏覽
添加回答
舉報
0/150
提交
取消