gpt4 book ai didi

go - 如何解决golang中 "missing Location in call to Date"的错误

转载 作者:数据小太阳 更新时间:2023-10-29 03:39:39 25 4
gpt4 key购买 nike

<分区>

我写了一个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])
}

但是当我运行这段代码时,它会给我以下错误:-

time: missing Location in call to Date

为什么会产生这个错误,我将如何解决这个错误?

请提出任何建议!

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com