我在程序中有以下代码,目标是确保一个项目在一个时间范围内可访问。出于某种原因,这是错误的。我记录了开始,结束和现在的时间。开始/结束日期通过JSON请求进入,没有时区。 time.Now()给出了一个时区。那是我的问题吗?我将如何解决它?GoLang解析time.Now()无时区?
func withinStartAndEnd(item Item) bool {
fmt.Println("Start Date", item.Start_date, "\n")
fmt.Println("End Date", item.End_date, "\n")
fmt.Println("Now:", time.Now(), "\n")
//BUG: For some reason event 0's are still not accessible within the timeframe. The fmt's above are to help look at it. time.Now() is printing MST.. maybe that's it?
/*
Start Date 2016-02-19 09:50:00 +0000 +0000
End Date 2016-02-19 10:00:00 +0000 +0000
Now: 2016-02-19 09:59:48.73003196 -0700 MST
2016/02/19 09:59:48 Item not accessible (#148)
*/
return item.Start_date.Before(time.Now()) && item.End_date.After(time.Now())
}
2016-02-19 Nathan Hyland