time.Time in go is stored as int64 plus a 32-bit nanosecond value, but if you use @JimB's answer, you will cause an integer overflow in the sec component, and comparisons such as time.Before() will not work.
This is because time.Unix(sec, nsec) adds an offset from 62135596800 seconds to sec , which represents the number of seconds between year 1 (zero time in Go) and 1970 (zero time in Unix).
@twotwotwo playground makes this clear at http://play.golang.org/p/i6S_T4-X3v , but here is the distilled version.
// number of seconds between Year 1 and 1970 (62135596800 seconds) unixToInternal := int64((1969*365 + 1969/4 - 1969/100 + 1969/400) * 24 * 60 * 60) // max1 gets time.Time struct: {-9223371974719179009 999999999} max1 := time.Unix(1<<63-1, 999999999) // max2 gets time.Time struct: {9223372036854775807 999999999} max2 := time.Unix(1<<63-1-unixToInternal, 999999999) // t0 is definitely before the year 292277026596 t0 := time.Date(2015, 9, 16, 19, 17, 23, 0, time.UTC) // t0 < max1 doesn't work: prints false fmt.Println(t0.Before(max1)) // max1 < t0 doesn't work: prints true fmt.Println(t0.After(max1)) fmt.Println(max1.Before(t0)) // t0 < max2 works: prints true fmt.Println(t0.Before(max2)) // max2 < t0 works: prints false fmt.Println(t0.After(max2)) fmt.Println(max2.Before(t0))
So, although this is a bit of a pain, you can use time.Unix(1<<63-62135596801, 999999999) if you want to use max time.Time , which is useful for comparisons such as finding the minimum value in a range of times.
source share