问题描述
我正在尝试解析Unix 时间戳,但我超出范围错误。这不是真的有意义,因为布局是正确的(如在golang文档):
I'm trying to parse an Unix timestamp but I get out of range error. That doesn't really makes sense to me because the layout is correct (as in the golang docs):
package main
import "fmt"
import "time"
func main() {
tm, err := time.Parse("1136239445", "1405544146")
if err !=nil{
panic(err)
}
fmt.Println(tm)
}
推荐答案
time.Parse strconv.ParseInt int64 创建时间戳time.Unix
time.Parsestrconv.ParseIntint64time.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)
}
输出:
2014-07-16 20:55:46 +0000 UTC
strconv.Atoi strconv.ParseInt
strconv.Atoistrconv.ParseInt
这篇关于如何解析golang中的unix时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!