第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在每天的特定時(shí)間運(yùn)行作業(yè)?

如何在每天的特定時(shí)間運(yùn)行作業(yè)?

Go
慕田峪4524236 2022-08-15 10:11:43
我想每天晚上9點(diǎn)打印出來(lái)。如何在 Go 中執(zhí)行此操作?do my job以下是我到目前為止所得到的:timer := time.NewTimer(3 * time.Second)for {    now := time.Now()    next := now.Add(time.Hour * 24)    todayNine := time.Date(next.Year(), next.Month(), next.Day(), 9, 0, 0, 0, next.Location()).AddDate(0, 0, -1)    todayFifteen := time.Date(next.Year(), next.Month(), next.Day(), 15, 0, 0, 0, next.Location()).AddDate(0, 0, -1)    todayEnd := time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location()).AddDate(0, 0,  -1)    if now.Before(todayNine) {        timer.Reset(todayNine.Sub(now))    } else if now.Before(todayFifteen) {        timer.Reset(todayFifteen.Sub(now))    } else if now.Before(todayEnd) {        timer.Reset(todayEnd.Sub(now))    }    <- timer.C    fmt.Println("do my job")}
查看完整描述

1 回答

?
德瑪西亞99

TA貢獻(xiàn)1770條經(jīng)驗(yàn) 獲得超3個(gè)贊

我會(huì)使用包。https://pkg.go.dev/github.com/robfig/croncron


文檔中的示例:


c := cron.New()

c.AddFunc("0 30 * * * *", func() { fmt.Println("Every hour on the half hour") })

c.AddFunc("@hourly",      func() { fmt.Println("Every hour") })

c.AddFunc("@every 1h30m", func() { fmt.Println("Every hour thirty") })

c.Start()

..

// Funcs are invoked in their own goroutine, asynchronously.

...

// Funcs may also be added to a running Cron

c.AddFunc("@daily", func() { fmt.Println("Every day") })

..

// Inspect the cron job entries' next and previous run times.

inspect(c.Entries())

..

c.Stop()  // Stop the scheduler (does not stop any jobs already running).


查看完整回答
反對(duì) 回復(fù) 2022-08-15
  • 1 回答
  • 0 關(guān)注
  • 89 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)