Advertisement
zergon321

Scheduled interval

Feb 18th, 2022
1,462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.31 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "time"
  6. )
  7.  
  8. func main() {
  9.     interval := 4 * time.Hour
  10.     now := time.Now().UTC()
  11.     offset := now.UnixNano() % int64(interval)
  12.     pastTime := now.Add(-time.Duration(offset))
  13.     futureTime := now.Add(interval - time.Duration(offset))
  14.  
  15.     fmt.Println(pastTime)
  16.     fmt.Println(futureTime)
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement