Go中的Time
字符串->time
time_str := "2014-12-04 13:27:54.758"
t, _ := time.Parse("2006-01-02 15:04:05", time_str)
fmt.Print(t)
输出为2014-12-04 13:27:54.758 +0000 UTC
已经成功转化,但是时区使用的是UTC.
需要分析的时间是本地时间, 所以上面的方法满足不了需求
time_str := "2014-12-04 13:27:54.758"
l, _ := time.LoadLocation("Local")
t, _ := time.ParseInLocation("2006-01-02 15:04:05", time_str, l)
fmt.Print(t)
输出为2014-12-04 13:27:54.758 +0800 CST
time->Unix
沿用前面的变量
fmt.Print(t.Unix())
输出为1417670874
Unix->time
fmt.Print(time.Unix(t.Unix(), 0).String())
输出为2014-12-04 13:27:54 +0800 CST