does anyone know what that’s about? I am trying to convert an int to a string here.
Time type is not equivalent to an int. If your need is a string representation, type Time
has a String()
method.
Sample code below (also available as a runnable Go Playground snippet):
package main
import (
"fmt"
"time"
)
// Nearby whatever
type Nearby struct {
id int
me int
you int
contactTime string
}
func main() {
s1 := Nearby{
id: 1,
me: 1,
you: 2,
contactTime: time.Now().String(), // <-- type Time has a String() method
}
fmt.Printf("%+v", s1)
}
Hope this helps. Cheers,
solved Cannot convert time.Now() to a string