第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法將 time.Now() 轉(zhuǎn)換為字符串

無法將 time.Now() 轉(zhuǎn)換為字符串

Go
Smart貓小萌 2023-04-24 17:07:32
我有這個結(jié)構(gòu):// Nearby whatevertype Nearby struct {    id          int    `json:"id,omitempty"`    me          int    `json:"me,omitempty"`    you         int    `json:"you,omitempty"`    contactTime string `json:"contactTime,omitempty"`}然后我稱之為:strconv.Itoa(time.Now())像這樣:s1 := Nearby{id: 1, me: 1, you: 2, contactTime: strconv.Itoa(time.Now())}但它說:> cannot use time.Now() (type time.Time) as type int in argument to> strconv.Itoa有誰知道那是什么?我想在這里將一個 int 轉(zhuǎn)換為一個字符串。
查看完整描述

1 回答

?
撒科打諢

TA貢獻1934條經(jīng)驗 獲得超2個贊

有誰知道那是什么?我想在這里將一個 int 轉(zhuǎn)換為一個字符串。


時間類型不等同于 int。如果您需要的是字符串表示,typeTime有一個String()方法。


下面的示例代碼(也可作為可運行的 Go Playground代碼段提供):


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)


}

希望這可以幫助。干杯,


查看完整回答
反對 回復(fù) 2023-04-24
  • 1 回答
  • 0 關(guān)注
  • 203 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號