datetime - Golang - 结构 : time. 时间

标签 datetime go

<分区>

我正在尝试将一个值转换为具有时间类型的结构。时间。

值为:

t := time.Now()
format := "2006-01-02 15:04:05"

然后我尝试将其放入结构中:

response.SetAppData[0].LiveDate = time.Parse(format, t.String())

但是我得到的错误是:

controllers/apps.go:1085: multiple-value time.Parse() in single-value context

我不确定我做错了什么。

谢谢

最佳答案

意思是time.Parse返回两个结果 time.Timeerror 值。您只分配给一个变量。

你应该这样做:

response.SetAppData[0].LiveDate, err = time.Parse(format, t.String())
if err != nil {
    // error handling here
}

关于datetime - Golang - 结构 : time. 时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36404635/

相关文章:

python - 从 Python featuretools 中的特征工程中排除当前行

python - 使用日期时间索引或列查询 Python Pandas DataFrame

go - 如何在 Go 中使用 Cli 访问一组命令?

http - 限制 HTTP 请求的速率(通过 http.HandlerFunc 中间件)

go - 为什么 golang 中的网络 IO 线程使用量会增加?

go - 我正在使用 go 语言打印到 POS 打印机,但汉字打印错误。 (英语可以)

java - 如果时间戳映射到数据库/从数据库映射,则 Timestamp#equals() 失败

iOS : Timezone Issue on Local timezone of iPhone device

c# - AddDays() 在 for 循环中

go - 使用带有 go/mgo 的嵌套结构进行部分更新