Creating a RFC 1123 compliant date for HTTP header creation on the CLI
man date
for whatever version of date your OS provides and use the correct switches to print (see man strftime
), from from left to right, with a space between each, first the date:
Day (Three letter abbreviation Mon-Tue-Wed...) followed by a comma ,,
the month (Three letter abbreviation Jan Feb Mar ...)
the year (4 digit notation 1970, 1971 ...)
and then time HH:MM:SS
.
And you might get something like Fri, 20 May 2016 20:22:33 GMT
env TZ=GMT; date '+%a, %d %b %Y %T %Z'
-
%T
is equivalent to%H:%M:%S
. -
%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.