Skip to content

Instantly share code, notes, and snippets.

@u110
Created January 8, 2020 13:50
Show Gist options
  • Save u110/8197afe481cafd1382d9ac117d5a7dbd to your computer and use it in GitHub Desktop.
Save u110/8197afe481cafd1382d9ac117d5a7dbd to your computer and use it in GitHub Desktop.
[go] time.Until
package main
import (
"log"
"time"
)
func main() {
log.Println("start.")
defer log.Println("end.")
quit := make(chan bool)
go func() {
// time.Sleep(time.Second)
timeString := "2020-01-08T22:50:00+09:00"
log.Println("wait until", timeString)
startAt, err := time.Parse(time.RFC3339, timeString)
if err != nil {
log.Fatal("Parse error.", err)
}
time.Sleep(time.Until(startAt))
quit <- true
}()
<-quit
}
@u110
Copy link
Author

u110 commented Jan 8, 2020

output

u110:~/go/src/golangProjects/sandbox $ go run timeUntil.go 
2020/01/08 22:49:39 start.
2020/01/08 22:49:39 wait until 2020-01-08T22:50:00+09:00
2020/01/08 22:50:00 end.

@u110
Copy link
Author

u110 commented Jan 8, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment