Tutorial by Examples

const timeFormat = "15 Monday January 2006" func ParseDate(s string) (time.Time, error) { t, err := time.Parse(timeFormat, s) if err != nil { // time.Time{} returns January 1, year 1, 00:00:00.000000000 UTC // which according to the source code is the zero va...
If you have a date stored as a string you will need to parse it. Use time.Parse. // time.Parse( format , date to parse) date, err := time.Parse("01/02/2006", "04/08/2017") if err != nil { panic(err) } fmt.Println(date) // Prints 2017-04-08 00:00:00 +00...
Sometime you will need to know, with 2 dates objects, if there are corresponding to the same date, or find which date is after the other. In Go, there is 4 way to compare dates: date1 == date2, returns true when the 2 are the same moment date1 != date2, returns true when the 2 are different mom...

Page 1 of 1