This is a creation in Article, where the information may have evolved or changed.
recently done projects to use the Golang language, encountered the problem of conversion of time format , referring to the online information to write their own code test, to successfully convert, put the code out for later use, but also for the need to view.
<span style= "FONT-SIZE:18PX;" >//time_format.gopackage mainimport ("FMT" "Time") Func main () {FMT. Println ("Hello world!") Returns the current time tnow: = times. Now ()//Time conversion to String,layout must be "2006-01-02 15:04:05" TimeNow: = Tnow.format ("2006-01-02 15:04:05") fmt. Println ("Tnow (Time format):", Tnow) fmt. Println ("Tnow (string format):", TimeNow)//string converted to time, the layout must be "2006-01-02 15:04:05" T, _: = times. Parse ("2006-01-02 15:04:05", "2014-06-15 08:37:18") fmt. Println ("t (time format)", T)//At some point before and after the trueorfalse: = T.after (tnow) If Trueorfalse = = true {fmt. Println ("t (2014-06-15 08:37:18) after Tnow!")} else {fmt. Println ("t (2014-06-15 08:37:18) before Tnow!")} Fmt. Println ()}</span>
Output Result:
Hello world!
Tnow (Time format): 2015-06-15 08:52:32.8861261 +0800 CST
Tnow (string format): 2015-06-15 08:52:32
T (time format) 2014-06-15 08:37:18 +0000 UTC
T (2014-06-15 08:37:18) before Tnow!