英文:
How do I format an unix timestamp to RFC3339 - golang?
问题
我需要将一个Unix时间戳(例如1392899576
)转换为RFC3339格式(例如1997-07-16T19:20+01:00
)。我尝试了下面的代码:
timeValue := "1392899576"
layout := time.RFC3339
t, _ := time.Parse(layout, timeValue)
fmt.Fprintf(w, "%s", t)
但返回的结果是:
0001-01-01 00:00:00 +0000 UTC
英文:
I need to convert a unix timestamp ( e.g 1392899576
) into RFC3339 ( e.g. 1997-07-16T19:20+01:00 ) . I've tried the code below
timeValue := "1392899576"
layout := time.RFC3339
t, _ := time.Parse(layout, timeValue)
fmt.Fprintf(w, "%s", t)
which returns
0001-01-01 00:00:00 +0000 UTC
答案1
得分: 25
“Parse”一词通常指的是将某个东西的字符串表示转换为相同东西的内部语言表示的过程。
你想要的是“Parse”的相反操作,即“Format”:
time.Unix(1392899576, 0).Format(time.RFC3339)
英文:
The term "Parse" usually means a procedure that converts a string representation of something into the internal language representation for the same thing.
What you want is the opposite of Parse, "Format":
time.Unix(1392899576, 0).Format(time.RFC3339)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论