123456789101112131415161718192021222324252627 |
- package timetask
- import (
- model "access-control-monitor/model/v1"
- "github.com/jaryhe/gopkgs/database"
- "time"
- )
- func clearAttendanceDay() {
- now := time.Now().Format("2006-01-02")
- attendance := model.WorkerAttendanceInfo{TabType:model.AttendanceTabDay}
- where := map[string]interface{}{
- "day_time <":now,
- }
- attendance.Delete(database.DB(), where)
- }
- //定时创建数据库
- func ClearAttendanceDay() {
- for {
- now := time.Now() //获取当前时间,放到now里面,要给next用
- next := now.Add(time.Hour * 24) //通过now偏移24小时
- next = time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location()) //获取下一个凌晨的日期
- t := time.NewTimer(next.Sub(now))//计算当前时间到凌晨的时间间隔,设置一个定时器
- <-t.C
- clearAttendanceDay()
- }
- }
|