Skip to content

Instantly share code, notes, and snippets.

@lsegal
Created February 8, 2018 02:44
Show Gist options
  • Save lsegal/267b81629cc7df93887d2509b3238fcf to your computer and use it in GitHub Desktop.
Save lsegal/267b81629cc7df93887d2509b3238fcf to your computer and use it in GitHub Desktop.
sleepy times for Go
package main
import (
"fmt"
"time"
)
func main() {
tm := time.Now()
tmu := time.Now().UTC()
fmt.Println("Current time:", tm)
fmt.Println("Current time UTC:", tmu)
fmt.Println("")
fmt.Println("Put your machine to sleep for 2 minutes now...")
<-time.After(1 * time.Minute)
now := time.Now()
fmt.Println("")
fmt.Println("The current time is: ", now)
fmt.Println("The previous time was: ", tm)
fmt.Println("The difference between these times is: ", now.Sub(tm))
nowu := time.Now().UTC()
fmt.Println("")
fmt.Println("The current UTC time is: ", nowu)
fmt.Println("The previous UTC time was: ", tmu)
fmt.Println("The difference between these UTC times is: ", nowu.Sub(tmu))
}
$ go run ./sleepy/main.go
Current time: 2018-02-07 18:40:47.221076456 -0800 PST m=+0.000345520
Current time UTC: 2018-02-08 02:40:47.221076519 +0000 UTC
Put your machine to sleep for 2 minutes now...
The current time is: 2018-02-07 18:42:44.393655472 -0800 PST m=+60.001694536
The previous time was: 2018-02-07 18:40:47.221076456 -0800 PST m=+0.000345520
The difference between these times is: 1m0.001349016s
The current UTC time is: 2018-02-08 02:42:44.393791308 +0000 UTC
The previous UTC time was: 2018-02-08 02:40:47.221076519 +0000 UTC
The difference between these UTC times is: 1m57.172714789s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment