如何在Go中将时间戳格式化为GMT?
I need to format a timestamp with RFC2616, the standard for HTTP dates. However, the standard says:
All HTTP date/time stamps MUST be represented in Greenwich Mean Time (GMT), without exception.
From a little digging GMT and UTC are not the same thing. Is there a proper way to convert a timestamp to GMT in Go?
0 提建议当前问题酬金
¥ 0 (可追加 ¥500)
支付方式
扫码支付
1 条回答 默认 最新
-
duanchi8836 2018-09-04 00:38关注
Use the http.TimeFormat layout to format times for HTTP headers. This layout assumes a time in the UTC location.
s := t.UTC().Format(http.TimeFormat)
If the time is known to be in UTC, then the call to UTC() can be skipped:
s := t.Format(http.TimeFormat)
本回答被题主选为最佳回答 , 对您是否有帮助呢? 本回答被专家选为最佳回答 , 对您是否有帮助呢? 本回答被题主和专家选为最佳回答 , 对您是否有帮助呢?举报按下Enter换行,Ctrl+Enter发表内容
查看更多回答(0条)