From 7402ad51a6255fb477b33b32d9e4f1b998d60661 Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Wed, 31 Oct 2012 09:13:37 -0700 Subject: [PATCH] update epoch --- examples/epoch/epoch.go | 12 +++++++++--- examples/epoch/epoch.sh | 11 +++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) 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