タグ

goとtimeに関するnabinnoのブックマーク (5)

  • Parsing RFC-3339 / ISO-8601 date-time string in Go

    I tried parsing the date string "2014-09-12T11:45:26.371Z" in Go. This time format is defined as: RFC-3339 date-time ISO-8601 date-time Code layout := "2014-09-12T11:45:26.371Z" str := "2014-11-12T11:45:26.371Z" t, err := time.Parse(layout , str) I got this error: parsing time "2014-11-12T11:47:39.489Z": month out of range How can I parse this date string?

    Parsing RFC-3339 / ISO-8601 date-time string in Go
  • Goでスリープしようとしてハマった - 今川館

    Pythonでスリープするときは import time time.sleep(1) # 1秒待つ time.sleep(0.5) # 0.5秒待つ こうすれば良いが、同じ感覚でGoでスリープしようとしたらうまくいかなかった。 import "time" time.Sleep(1) // 1秒待つ(?) どうなるかというと、やけに早く戻ってきてしまうのである。 ちなみに、こっちをやるとコンパイルエラーになってしまう。 time.Sleep(0.5) // constant 0.5 truncated to integer Goのtime.Sleepの引数はDurationという型 https://golang.org/pkg/time/#Sleep golangのドキュメントを見ると、time.Sleepの引数にはtime.Durationという型を受け付ける。 そして、time.Dura

    Goでスリープしようとしてハマった - 今川館
  • time package - time - Go Packages

    Package time provides functionality for measuring and displaying time. The calendrical calculations always assume a Gregorian calendar, with no leap seconds. Monotonic Clocks ¶Operating systems provide both a “wall clock,” which is subject to changes for clock synchronization, and a “monotonic clock,” which is not. The general rule is that the wall clock is for telling time and the monotonic clock

    nabinno
    nabinno 2019/08/04
    Duration, Location, Month, ParseError, Ticker, Time, Timer, and Weekday
  • Goで一定周期で何かを行う方法 - Qiita

    Goでは言語組み込みの並行処理のサポートがあるから、一定の周期で何らかの処理を行うのは簡単だ。その処理のためのgoroutineを作って、それを一定の間隔で目覚させて実際の処理を行わせるようにすれば良い。 Sleep 一番簡単な方法は無限ループを回して、ループの最後にtime.Sleepで一定時間休むという方法だろう。 go func() { for { // ここでなにかを行う time.Sleep(3 * time.Second) // 3秒休む } }() この方法は手っ取り早いけど、Sleepを途中で中断することはできない。たとえばこのgoroutineがいらなくなったときにそれをチャネルで通知してgoroutineを終了させるとか、あるいは早めに目覚めさせてループの先頭に復帰させるとか、そういったことはSleepが返ってくるまで行うことができない。 Ticker 「多重化できない

    Goで一定周期で何かを行う方法 - Qiita
  • time package - time - Go Packages

    Package time provides functionality for measuring and displaying time. The calendrical calculations always assume a Gregorian calendar, with no leap seconds. Monotonic Clocks ¶Operating systems provide both a “wall clock,” which is subject to changes for clock synchronization, and a “monotonic clock,” which is not. The general rule is that the wall clock is for telling time and the monotonic clock

  • 1