package main import ( "time" ) // 获取5分钟为间隔的下一个查询时间 func getNextQueryTime() time.Time { now := time.Now() minute := now.Minute() nextMinute := ((minute / 5) + 1) * 5 var nextHour int if nextMinute >= 60 { nextMinute = 0 nextHour = now.Hour() + 1 if nextHour >= 24 { nextHour = 0 } } else { nextHour = now.Hour() } return time.Date(now.Year(), now.Month(), now.Day(), nextHour, nextMinute, 0, 0, now.Location()) } // 获取下一个整点时间 func getNextHourTime() time.Time { now := time.Now() nextHour := now.Hour() + 1 if nextHour >= 24 { nextHour = 0 // 如果是23点,则下一小时是次日的0点 if now.Hour() == 23 { tomorrow := now.AddDate(0, 0, 1) return time.Date(tomorrow.Year(), tomorrow.Month(), tomorrow.Day(), 0, 0, 0, 0, now.Location()) } } return time.Date(now.Year(), now.Month(), now.Day(), nextHour, 0, 0, 0, now.Location()) } // 判断是否接近整点(前后2分钟内) func isNearHour() bool { now := time.Now() minute := now.Minute() return minute >= 58 || minute <= 2 }