Obtaining a Unix Timestamp in Go Language (current time in seconds since epoch)

前端 未结 4 594
既然无缘
既然无缘 2020-12-13 05:30

I have some code written in Go which I am trying to update to work with the latest weekly builds. (It was last built under r60). Everything is now working except for the fol

4条回答
  •  粉色の甜心
    2020-12-13 06:01

    If you want it as string just convert it via strconv:

    package main
    
    import (
        "fmt"
        "strconv"
        "time"
    )
    
    func main() {
        timestamp := strconv.FormatInt(time.Now().UTC().UnixNano(), 10)
        fmt.Println(timestamp) // prints: 1436773875771421417
    }
    

提交回复
热议问题