go string to time (字符串转时间戳)
文章目录
//字符串转时间戳 YmdHis 格式 比如 2022-07-06 15:00:00
func strToUnixTime(YmdHis string) (int64, error) {
loc, _ := time.LoadLocation("Local")
theTime, err := time.ParseInLocation("2006-01-02 15:04:05", YmdHis, loc)
if err != nil {
return 0, err
}
unixTime := theTime.Unix()
return unixTime, nil
}我们调用一下试试:
func TestStrToTome(t *testing.T) {
t.Log(strToUnixTime("2022-07-22 15:11:11"))
}输出:
1658473871
谢谢您的观看,欢迎关注我的公众号。

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论