This is a creation in Article, where the information may have evolved or changed.
First of all, Golang language design has a guy called xxnuts, really is a pervert, the time of the original design in the 2006-01-02 15:04:05
In fact, this date is meaningful:
2006-01-02t15:04:05z07:00
The meaning of each number:
1 2 3 4 5 6 7 Month Day seconds time zone
Common methods:
1 totime Format (parsing):
Usage One: Use the number of milliseconds
T: = time. Unix (1362984425, 0) NT: = T.format ("2006-01-02 15:04:05") fmt. Println (NT)
Usage two: Format with fixed string to get time object
Const TIMEFORMAT = "2006-01-02 15:04:05" func testxyz (t *testing. T) {T,err:=time. Parse (TimeFormat, "2013-08-11 11:18:46") l.println (t)}
2 ToString Time formatting formatting
Package Mainimport ( "FMT" "Time") Func main () { T: = time. Secondstolocaltime (1305861602) t.zoneoffset = -4*60*60 fmt. Println (T.format ("2006-01-02 15:04:05-0700"))}//= "2011-05-20 03:20:02-0400"
3 format string type
Of course, if there is no type of formatting you want, then look at the following schedule:
Const ( Ansic = "Mon Jan _2 15:04:05 2006" unixdate = "Mon Jan _2 15:04:05 MST 2006 " rubydate =" Mon Jan, 15:04:05-0700 2006 " RFC822 &N Bsp = "15:04 MST"//RFC822 with numeric zone RFC850 = "Monday, 02-jan-06 15:04:05 MST" &N Bsp rfc822z = "15:04-0700" RFC1123 = "Mon, Jan 2006 15:04: MST "//RFC1123 with numeric zone RFC3339 =" 2006-01-02t15:04:05z07:00 " rfc1123z &NB Sp;= "Mon, 2006 15:04:05-0700" Rfc3339nano = "2006-01-02t15:04:05.999999999z07:00"//Handy Ti Me stamps. Stamp = "Jan _2 15:04:05" Kitchen = "3:04pm" Stampmilli = "Jan _2 15:04:05.000" stampmicro = "Jan _2 15:04:05.000000" Stampnano = "Jan _2 15:04:05 .000000000 ")