学无先后,达者为师

网站首页 编程语言 正文

golang:日期与时间戳相互转换

作者:皇小邪 更新时间: 2022-02-24 编程语言

1、时间戳转日期:

    timestamp := 1602482956

    timeobj := time.Unix(int64(timestamp), 0)

    date := timeobj.Format("2006-01-02 15:04:05")

    fmt.Println(date)

运行结果:

2、日期转时间戳:

    str := "2020-10-12 14:19:53"

    tmp := "2006-01-02 15:04:05"

    res, _ := time.ParseInLocation(tmp, str, time.Local)

    fmt.Println(res.Unix())

原文链接:https://blog.csdn.net/huangjinao/article/details/109026949

栏目分类
最近更新