epoch
This commit is contained in:
parent
918d09238a
commit
47dbd1c9e9
@ -1,4 +1,4 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import ("fmt"; "strings")
|
import ("fmt"; "strings")
|
||||||
|
|
||||||
|
21
051-epoch.go
21
051-epoch.go
@ -1,13 +1,20 @@
|
|||||||
package main
|
package main // Use `time.Now` with `Unix` or `UnixNane` to get
|
||||||
|
// elapsed time since the Unix epoch.
|
||||||
import ("time"; "fmt")
|
import "time"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
secs := now.Unix()
|
secs := now.Unix()
|
||||||
nanos := now.UnixNano()
|
nanos := now.UnixNano()
|
||||||
millis := nanos / 1000000
|
millis := nanos / 1000000 // There is no `UnixMillis`.
|
||||||
fmt.Println("Seconds since epoch:", secs)
|
println("Secs: ", secs)
|
||||||
fmt.Println("Millis since epoch:", millis)
|
println("Millis:", millis)
|
||||||
fmt.Println("Nanos since epoch:", nanos)
|
println("Nanos: ", nanos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
$ go run 051-epoch.go
|
||||||
|
Secs: 1348240948
|
||||||
|
Millis: 1348240948517
|
||||||
|
Nanos: 1348240948517870000
|
||||||
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user