For New Go Programmers.
Key point about formats: the correct component values (ex. 2006 for year, 15 for hour) must be used.
const Format1 = "Jan 2, 2006"
const Format2 = "2006-01-02 15:04:05"
...
var date1 time.Time
input1 := "Apr 1, 2017"
date1, _ = time.Parse(Format1, input1) // probably want to check for error
output1 := date1.AddDate(1, 1, 1).Format(Format2) // add 1 yr, 1 mo, 1 day & return formatted value
log.Println(output1) // prints 2018-05-02 00:00:00
I know there are many posts about dates, but this simple concept is often covered over with lots of other info.
评论:
metamatic:
jayposs:
j_d_q:Cool
jayposs:Godoc
time
constants lists the possibilities
Definitely the Go to for all the details. Think when you first read it, you miss the point of how easy it is to work with date formats.
