I am trying to hash the timestamp in my program:
h := md5.New()
t := time.Now()
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?
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
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.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.