首页 > 其他 > 详细

epoch _ golang

时间:2015-03-26 14:38:50      阅读:274      评论:0      收藏:0      [点我收藏+]

A common requirement in programs is getting the number of seconds, millisecond, or nanoseconds since Unix epoch. Here‘s how to do it in Go

package main

import (
    "fmt"
    "time"
)

func main() {

    now := time.Now()
    secs := now.Unix()
    nanos := now.UnixNano()
    fmt.Println(now)

    millis := nanos / 1000000
    fmt.Println(secs)
    fmt.Println(millis)
    fmt.Println(nanos)
    fmt.Println(time.Unix(secs, 0))
    fmt.Println(time.Unix(0, nanos))
}
1427346457
1427346457254
1427346457254439916
2015-03-26 13:07:37 +0800 CST
2015-03-26 13:07:37.254439916 +0800 CST

总结 :

  1 : ...

epoch _ golang

原文:http://www.cnblogs.com/jackkiexu/p/4368411.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!