大网数据广告活动
服务器运维问答

Creating a RFC 1123 compliant date for HTTP header creation on the CLI

· 52CE 我爱测

I'm trying to create a HTTP 1/1 compliant date header using standard unix date(1) in order to post this to a RESTful server using curl or similar. Any ideas what format to pass to date(1) to get this to be RFC 1123 compliant? Man…

问题原文

原帖链接 · Brad · CC BY-SA 3.0

I'm trying to create a HTTP 1/1 compliant date header using standard unix date(1) in order to post this to a RESTful server using curl or similar.

Any ideas what format to pass to date(1) to get this to be RFC 1123 compliant?

Many thanks

社区高分解答

原帖链接 · Weihang Jian · CC BY-SA 4.0

env TZ=GMT; date '+%a, %d %b %Y %T %Z'

  1. %T is equivalent to %H:%M:%S.
  2. %Z is replaced by the time zone name.

The solution by @brad, DATE=$(date -u +%a,\ %d\ %b\ %Y\ %H:%M:%S\ GMT), would be incorrect if the time zone setting of your system is not GMT. For example:

env TZ=Asia/Taipei; date -u +%a,\ %d\ %b\ %Y\ %H:%M:%S\ GMT

%H:%M:%S would be GMT+8 while the output is GMT, but should be CST.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-05-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。