GO教程
GO控制语句
GO高级

GO Epoch

GO Epoch

在 Go 中,我们可以产生以秒、毫秒、纳秒为单位的时间。 time 包中包含所需的方法,例如 secs、nanos 等,它们对我们有帮助。
参考时间是 unix epoch。我们也可以将纳秒或毫秒转换为时间格式。
package main
import "fmt"
import "time"
func main() {
    p := fmt.Println
    current_time := time.Now()
    secs := current_time.Unix()
    nanos := current_time.UnixNano()
    fmt.Println(current_time)
    millis := nanos / 1000000
    p(secs)
    p(millis)
    p(nanos)
    p(time.Unix(secs, 0))
    p(time.Unix(0, nanos))
}
输出:
2017-10-06 17:34:13.971527666 +0530 IST m=+0.000334769
1507291453
1507291453971
1507291453971527666
2017-10-06 17:34:13 +0530 IST
2017-10-06 17:34:13.971527666 +0530 IST

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4