Golang解析时间戳格式

huangapple go评论76阅读模式
英文:

Golang parsing timestamp format

问题

我有一个解析 JSON 中时间戳的电报服务。

我在 JSON 消息中获取到的时间戳示例为:

2017-09-04T04:00:00

但是在电报设置中,我无法正确设置解析方式,我了解这是使用 Go 语言编写的。

time_format: "2006-01-02T15:04:05Z"

我遇到了一个错误:

ERROR: 格式"2006-01-02T15:04:05Z07:00"导致错误:将时间"2017-09-04T04:00:00"解析为"2006-01-02T15:04:05Z07:00"时出错:无法将""解析为"Z07:00"

但是我无法将其设置为正常工作。

英文:

I have a telegraph service that parses a timestamp in json.

I get this timestamp for example in json messages:

2017-09-04T04:00:00

But in the telegraph settings I can't set the parsing correctly, which I understand is in the go language.

time_format: "2006-01-02T15:04:05Z"

I am getting an error:

ERROR: format "2006-01-02T15:04:05Z07:00" resulted in error: parsing time "2017-09-04T04:00:00" as "2006-01-02T15:04:05Z07:00": cannot parse "" as "Z07:00"

And somehow I can't set this to work.

答案1

得分: 3

你的时间布局包含一个时区组件,但你的时间没有。尝试使用以下布局:

"2006-01-02T15:04:05"

英文:

Your time layout includes a timezone component but your time doesn't. Try this layout:

"2006-01-02T15:04:05"

huangapple
  • 本文由 发表于 2023年3月21日 17:51:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75799611.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定