无法将time.Now()转换为字符串

I have this struct:

// Nearby whatever
type Nearby struct {
    id          int    `json:"id,omitempty"`
    me          int    `json:"me,omitempty"`
    you         int    `json:"you,omitempty"`
    contactTime string `json:"contactTime,omitempty"`
}

and then I call this:

strconv.Itoa(time.Now())

like so:

s1 := Nearby{id: 1, me: 1, you: 2, contactTime: strconv.Itoa(time.Now())}

but it says:

> cannot use time.Now() (type time.Time) as type int in argument to
> strconv.Itoa

does anyone know what that's about? I am trying to convert an int to a string here.

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,