Documentation ¶
Overview ¶
Package unixtime provides helper functions to convert between Go time values and Unix time values in milli- and microseconds.
The package has been created in response to Ian Lance Taylor's suggestion in the discussion of the Go issue #27782. A former issue discussing the same functionality has been #18935.
https://github.com/golang/go/issues/27782 https://github.com/golang/go/issues/18935
Example ¶
package main import ( "fmt" "log" "time" "github.com/ulikunitz/unixtime" ) func main() { t, err := time.Parse(time.RFC3339Nano, "1961-04-12T09:06:59.7+03:00") if err != nil { log.Fatalf("Parse error %s", err) } ms := unixtime.Milli(t) fmt.Printf("Unix time: %d ms\n", ms) tms := unixtime.FromMilli(ms) fmt.Printf("FromMilli: %s\n", tms.Format(time.RFC3339Nano)) µs := unixtime.Micro(t) fmt.Printf("Unix time: %d µs\n", µs) tµs := unixtime.FromMicro(µs) fmt.Printf("FromMicro: %s\n", tµs.Format(time.RFC3339Nano)) }
Output: Unix time: -275248380300 ms FromMilli: 1961-04-12T07:06:59.7+01:00 Unix time: -275248380300000 µs FromMicro: 1961-04-12T07:06:59.7+01:00
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.