diff --git a/examples/epoch/epoch.go b/examples/epoch/epoch.go index ed7f442..ff37ce5 100644 --- a/examples/epoch/epoch.go +++ b/examples/epoch/epoch.go @@ -12,24 +12,18 @@ import ( func main() { - // Use `time.Now` with `Unix` or `UnixNano` to get - // elapsed time since the Unix epoch in seconds or - // nanoseconds, respectively. + // Use `time.Now` with `Unix` or `UnixMilli` or `UnixNano` + // to get elapsed time since the Unix epoch in seconds or + // milliseconds or nanoseconds, respectively. 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 - // divide from nanoseconds. - millis := nanos / 1000000 - fmt.Println(secs) - fmt.Println(millis) - fmt.Println(nanos) + fmt.Println(now.Unix()) + fmt.Println(now.UnixMilli()) + fmt.Println(now.UnixNano()) // 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)) + fmt.Println(time.Unix(now.Unix(), 0)) + fmt.Println(time.Unix(0, now.UnixNano())) } diff --git a/examples/epoch/epoch.hash b/examples/epoch/epoch.hash index ad0a471..e0920da 100644 --- a/examples/epoch/epoch.hash +++ b/examples/epoch/epoch.hash @@ -1,2 +1,2 @@ -3b1fc502f41a978f1c8150335801aa9096db8954 -0ooeler0RfR +53610b08e885c8a36dc1a2c63a70e415ce6dfe2a +LSdohP_slOu diff --git a/public/epoch b/public/epoch index 0998c94..3d69363 100644 --- a/public/epoch +++ b/public/epoch @@ -44,7 +44,7 @@ Here’s how to do it in Go.
package main
Use time.Now
with Unix
or UnixNano
to get
-elapsed time since the Unix epoch in seconds or
-nanoseconds, respectively.
Use time.Now
with Unix
or UnixMilli
or UnixNano
+to get elapsed time since the Unix epoch in seconds or
+milliseconds or nanoseconds, respectively.
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
-divide from nanoseconds.
- millis := nanos / 1000000 - fmt.Println(secs) - fmt.Println(millis) - fmt.Println(nanos) +fmt.Println(now.Unix()) + fmt.Println(now.UnixMilli()) + fmt.Println(now.UnixNano())
time
.
- fmt.Println(time.Unix(secs, 0)) - fmt.Println(time.Unix(0, nanos)) + fmt.Println(time.Unix(now.Unix(), 0)) + fmt.Println(time.Unix(0, now.UnixNano())) }