various time

This commit is contained in:
Mark McGranaghan 2012-09-19 07:39:43 -07:00
parent 1a21dcacfa
commit e1a8b31f00
4 changed files with 54 additions and 12 deletions

13
README
View File

@ -33,18 +33,8 @@ gobyexample.com signups
* updates forever
* no drm
= source
* popular github libraries
* mailing list questions
* stack overflow questions
* handbook format
* rosetta stone
* building an actual fucking app
* ruby and nodejs stdlib
* ruby and nodejs killer apps
= topics
* time
* time formatting
* connection pool
* typed json parse/unparse
* web app
@ -62,7 +52,6 @@ gobyexample.com signups
* hipache port
* ssh
* dns
* timers
* tty
* iota
* oauth for google domains

15
src/xx-tickers.go Normal file
View File

@ -0,0 +1,15 @@
package main
import ("time"; "fmt")
func main() {
ticker := time.NewTicker(time.Millisecond * 500)
go func() {
for t := range ticker.C {
fmt.Println("Tick at", t)
}
}()
time.Sleep(time.Millisecond * 3000)
ticker.Stop()
fmt.Println("Ticker stopped")
}

18
src/xx-time.go Normal file
View File

@ -0,0 +1,18 @@
package main
import ("time"; "fmt")
func main() {
now := time.Now()
fmt.Println(now)
then := time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
fmt.Println(then)
diff := now.Sub(then)
fmt.Println(diff)
// extract parts
// add duration
// check before / after
}

20
src/xx-timers.go Normal file
View File

@ -0,0 +1,20 @@
package main
import ("time"; "fmt")
func main() {
timer1 := time.NewTimer(time.Millisecond * 500)
<- timer1.C
fmt.Println("Timer 1 expired")
stopped1 := timer1.Stop()
fmt.Println("Timer 2 stopped:", stopped1)
timer2 := time.NewTimer(time.Second)
go func() {
<- timer2.C
fmt.Println("Timer 2 expired")
}()
time.Sleep(time.Millisecond * 500)
stopped2 := timer2.Stop()
fmt.Println("Timer 2 stopped:", stopped2)
}