go 整分钟开始执行程序

前言

有时候我们的程序要求整分钟开始运行,这时候就需要对当前时间进行判断

package main

import (
	"fmt"
	"time"
)

func main() {
	for {
		nowTime := time.Now().Unix()
		//判断是否是整分钟,执行一次我们要运行的程序,跳出循环
		if nowTime%60 == 0 {
			go operation()
			break
		}
		fmt.Println(nowTime % 60)
		time.Sleep(time.Second)
	}

	select {}
}

func operation() {
	for {
		fmt.Println("operation...")
		time.Sleep(time.Second)
	}
}
原文地址:https://www.cnblogs.com/niuben/p/14710510.html