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?
Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.Visit Stack Exchange
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.Sign up to join this community
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
And you might get something like
Fri, 20 May 2016 20:22:33 GMT
DATE=$(date -u +%a,\ %d\ %b\ %Y\ %H:%M:%S\ GMT)in the end... not sure if these switches are right, but it seems to work.
env TZ=GMT; date '+%a, %d %b %Y %T %Z'
%Tis equivalent to
%Zis 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.