google / uuid

Go package for UUIDs based on RFC 4122 and DCE 1.1: Authentication and Security Services.
BSD 3-Clause "New" or "Revised" License
5.24k stars 363 forks source link

Getting time #81

Closed pedroalbanese closed 3 years ago

pedroalbanese commented 3 years ago

Greetings !!

How do I print the time of the parsed UUID?

Thanks in advance.

lvndry commented 3 years ago

I think that's what you're looking for: https://pkg.go.dev/github.com/google/uuid#UUID.Time

pborman commented 3 years ago

@lvndry is correct, just do: fmt.Printf("%v\n", uuid.Time())

pedroalbanese commented 3 years ago

        buf := new(bytes.Buffer)
        buf.ReadFrom(lreader)
        s := buf.String() 

        uuid, _ := uuid.Parse(s)
        fmt.Printf("Successfully parsed UID : %s\n", uuid)

        id := uuid
        t := id.Time()
        sec, nsec := t.UnixTime()
        timeStamp := time.Unix(sec, nsec)
        fmt.Printf("The id was generated at : %v \n", timeStamp.Format("2006-01-02 Mon 15:04:05.000Z -0700"))```
fishjam commented 7 months ago

is your time right after parse? this is my test code and result

timeGenerated := time.Unix(uuid.New().Time().UnixTime())
fmt.Printf("timeGenerated=%d, %s", timeGenerated.Unix(), timeGenerated.Format(time.DateTime))