Md5 on timestamp


(Sara D) #1

I am trying to hash the timestamp in my program:

h := md5.New()
t := time.Now()
io.WriteString(h, t)

Here’s what I get:

cannot use t (type time.Time) as type string in argument to io.WriteString

…and I cannot convert it to type String, or at least with what I have tried so far. Any ideas?


(Johan Dahl) #2

Hi

https://golang.org/pkg/time/#Time.Format is the function you want to use. There is also predefined formats for some common formats: https://golang.org/pkg/time/#pkg-constants


(Anyaddres) #3

How about this? https://play.golang.org/p/_e2CBGodmsI. You can call the String() method directly on the time instance. That will use the default format for the time string. Alternatively you could specify a format that you choose but you would need to be consistent.