好好爱自己!

How to parse unix timestamp to time.Time

 

The time.Parse function does not do Unix timestamps. Instead you can use strconv.ParseInt to parse the string to int64 and create the timestamp with time.Unix:

package main

import (
    "fmt"
    "time"
    "strconv"
)

func main() {
    i, err := strconv.ParseInt("1405544146", 10, 64)
    if err != nil {
        panic(err)
    }
    tm := time.Unix(i, 0)
    fmt.Println(tm)
}

Output:

2014-07-16 20:55:46 +0000 UTC
posted @ 2019-08-22 09:28  立志做一个好的程序员  阅读(147)  评论(0编辑  收藏  举报

不断学习创作,与自己快乐相处