func main() {
t := time.UTC()
s := t.Format("20060102")
fmt.Println(t, "=>", s)
}
except for knowing the standard date, a fact I believe is more
memorable than all the magic format flags and verbs in strftime, if
not in printf.
-rob
The time package has documentation that describes why.
http://golang.org/pkg/time/
Time format strings are specified by writing a specific date/time in the
format you'd like. Which is "Mon Jan 2 15:04:05 MST 2006"
"20060102" is just this date in a certain format.
The date 15th September 2011 would be "20110915" in that format.
package main
import "fmt"
import "time"
func main() {
t,err := time.Parse("20060102","20110915")
if err != nil {panic(err)}
fmt.Println(t)
}
will output:
Sun Sep 15 00:00:00 +0000 2011
Note: the day of the week is incorrect because time.Parse() will only
set time values we sent it and I didn't specify a day of the week.
- jessta
Note: this incorrect behavior has been corrected in tip by making
Weekday a method.
http://code.google.com/p/go/source/detail?r=ceeedb519c4a
01/02 03:04:05PM '06 -0700
godoc time | grep 01/02
> I wish the time package documentation printed it out this way...godoc time | grep 01/02