This is a creation in Article, where the information may have evolved or changed.
Golang Time Processing
Related package "Time"
Current time stamp
Fmt. Println (time. Now (). Unix ()) # 1389058332
Current Format Time
Fmt. Println (time. Now (). Format ("2006-01-02 15:04:05")) # This is a wonderful, must be this time point, said to be the day of the birth of Go, memory method: 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
The_time: = time. Date (1, 7, 5, 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
Example
Package Mainimport ("FMT" "Time") const (Date = "2006-01-02" shortdate = "06-01-02" Times = "15:04:02" Shorttime = "15:04" datetime = "2006-01-02 15:04:02" newdatetime = "2006/01/02 15~04~02" newtime = "15~04~02 ") func main () {thisdate: =" 2014-03-17 14:55:06 "Timeformatdate, _: = time. Parse (datetime, Thisdate) fmt. Println (timeformatdate) Convdate: = Timeformatdate. Format (date) Convshortdate: = Timeformatdate. Format (shortdate) Convtime: = Timeformatdate. Format (times) Convshorttime: = Timeformatdate. Format (shorttime) Convnewdatetime: = Timeformatdate. Format (newdatetime) Convnewtime: = Timeformatdate. Format (NewTime) fmt. Println (convdate) fmt. Println (convshortdate) fmt. Println (Convtime) fmt. Println (Convshorttime) fmt. Println (Convnewdatetime) fmt. Println (Convnewtime)}
formatting the current time
Lasttime, _: = time. Now (). Format ("2006-01-02 15:04:05")