我需要在某个时间段(例如 2015 年 8 月 17 日到 2015 年 10 月 14 日之间的每个星期日)之间获取一周中的特定一天,所以我最终得到了这个。
onDate, err := time.Parse(dateFormat, startDate)
if err != nil {
logr.Println(err)
}
offDate, err := time.Parse(dateFormat, stopDate)
if err != nil {
logr.Println(err)
}
weekday := onDate.Weekday()
getDay := int(weekday)
a := onDate.YearDay()
b := offDate.YearDay()
var date string
var z time.Time
// Sundaytime1 is entered in the browser and will always be the same
if sundayTime1 != "" && getDay == 0 {
for a <= b {
z := onDate.AddDate(0, 0, 7)
date := time.Parse(dateFormat, z)
fmt.Println(onDate)
_, err = que.Exec(studyID, msgid, date, sundayTime1, 0, 0)
if err != nil {
fmt.Println(err)
}
fmt.Println("I'm a Sunday!")
a = a + 7
}
}
这确实增加了一天,但它只增加了一次,所以它重复返回 2015-08-23 00:00:00 +0000 UTC
。我似乎无法让它只返回 2015-08-23
但它确实只在这段时间的每个星期日执行一个数据库条目。但它是错误的日期,它不应该包括时间。缺点是我在一周的每个可能的开始日都有其中之一。有没有更好的方法来处理这个问题,以及我如何在没有时间的情况下只得到 2015-08-23
。
最佳答案
这可能对您有用:http://play.golang.org/p/UGnV8kPrA3
当您处理时间实例时,结束日期在语义上是时间实例之前的日期 2015-10-14T00:00:00
+ 1 天
关于mysql - golang 在一周的特定日子(即每个星期五)采取行动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32062947/