time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
The above code gives us a timestamp but, what if I want to fetch only the date part and the time part separately? Is it possible to use split()?
You can use math/rand
to generate a random date like this:
import (
"fmt"
"math/rand"
"time"
)
func randate() time.Time {
min := time.Date(1970, 1, 0, 0, 0, 0, 0, time.UTC).Unix()
max := time.Date(2070, 1, 0, 0, 0, 0, 0, time.UTC).Unix()
delta := max - min
sec := rand.Int63n(delta) + min
return time.Unix(sec, 0)
}