This is a creation in Article, where the information may have evolved or changed.
Abstract: Like Python, golang time processing is relatively convenient, following the time processing of the previous python to expand
Golang Time Processing
Related package "Time"
Time stamp
Current time stamp
fmt.Println(time.Now().Unix())# 1389058332
STR format time
Current format time
fmt.Println(time.Now().Format("2006-01-02 15:04:05")) // 这是个奇葩,必须是这个时间点, 据说是go诞生之日, 记忆方法:6-1-2-3-4-5# 2014-01-07 09:42:20
timestamp to str format time
str_time := time. Unix (1389058332, 0). Format ("2006-01-02 15:04:05") fmt. Println (str_time) # 2014-01-07 09:32:12
STR format time-to-timestamp
This is more trouble.
the_time := time.Date(2014, 1, 7, 5, 50, 4, 0, time.Local)unix_time := the_time.Unix()fmt.Println(unix_time)# 389045004
There is also a way to use time . Parse
the_time, err := time.Parse("2006-01-02 15:04:05", "2014-01-08 09:04:41")if err == nil { unix_time := the_time.Unix()fmt.Println(unix_time)}# 1389171881
Transferred from: https://my.oschina.net/1123581321/blog/190942
Package Mainimport ( "FMT" "Time") Func main () { T, _: = time. Parse ("2006-01-02 15:04:05", "2016-04-20 16:23:00") FMT. Println (T.unix ()) y, m, D: = time. Unix (1466344320, 0). Date () FMT. Println (Y, M, D) the string after//format must be 2006-01-02 15:04:05, it is said that go is the fmt that was born this time . Println (time. Now (). Format ("2006-01-02 15:04:05")) FMT. Println (time. Now (). Format ("2006-01-02")) FMT. Println (time. Now (). Format ("20060102")) Select {Case <-time. After (5 * time. Second): FMT. Println ("after 5 second") } c: = time. Tick (Ten * time). Second) for now : = Range C { FMT. Println (now) } }