Go / golang time.Now().UnixNano() convert to milliseconds?

后端 未结 5 1469
栀梦
栀梦 2020-12-07 16:11

How can I get Unix time in Go in milliseconds?

I have the following function:

func makeTimestamp() int64 {
    return time.Now().UnixNano() % 1e6 / 1         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 17:02

    Keep it simple.

    func NowAsUnixMilli() int64 {
        return time.Now().UnixNano() / 1e6
    }
    

提交回复
热议问题