Created
January 8, 2020 13:50
-
-
Save u110/8197afe481cafd1382d9ac117d5a7dbd to your computer and use it in GitHub Desktop.
[go] time.Until
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://golang.org/pkg/time/#Until