亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何解決golang中“調用日期時缺少位置”的錯誤

如何解決golang中“調用日期時缺少位置”的錯誤

Go
慕妹3242003 2023-05-04 17:35:33
我寫了一個 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")
查看完整回答
反對 回復 2023-05-04
  • 1 回答
  • 0 關注
  • 135 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號