diff --git a/examples/epoch/epoch.go b/examples/epoch/epoch.go index 1b2ac4e..5752281 100644 --- a/examples/epoch/epoch.go +++ b/examples/epoch/epoch.go @@ -16,12 +16,18 @@ func main() { now := time.Now() secs := now.Unix() nanos := now.UnixNano() + fmt.Println(now) // Note that there is no `UnixMillis`, so to get the // milliseconds since epoch you'll need to manually // dive from nanoseconds. millis := nanos / 1000000 - fmt.Println("secs: ", secs) - fmt.Println("millis:", millis) - fmt.Println("nanos: ", nanos) + fmt.Println(secs) + fmt.Println(millis) + fmt.Println(nanos) + + // You can also convert integer seconds or nanoseconds + // since the epoch into the corresponding `time`. + fmt.Println(time.Unix(secs, 0)) + fmt.Println(time.Unix(0, nanos)) } diff --git a/examples/epoch/epoch.sh b/examples/epoch/epoch.sh index a59ee7b..ec3092e 100644 --- a/examples/epoch/epoch.sh +++ b/examples/epoch/epoch.sh @@ -1,4 +1,7 @@ -$ go run epoch.go -Secs: 1348240948 -Millis: 1348240948517 -Nanos: 1348240948517870000 +$ go run epoch.go +2012-10-31 16:13:58.292387 +0000 UTC +1351700038 +1351700038292 +1351700038292387000 +2012-10-31 16:13:58 +0000 UTC +2012-10-31 16:13:58.292387 +0000 UTC