How to convert to / get RFC822 date in bash/linux?

2.6k views Asked by At

Looking at date's man page, I couldn't find a standard way to convert to rfc822 (eg: from unix timestamp). I took a brief look at the spec, but I don't know enough about the subject matter to get the format right. Is there a easy way to convert to rfc822 with standard linux terminal tools?

1

There are 1 answers

0
rodrigo On BEST ANSWER

According to man 1 date:

-R, --rfc-email

output date and time in RFC 5322 format. Example: Mon, 14 Aug 2006 02:34:56 -0600

And it looks like RFC5322:

[...] is a revision of Request For Comments (RFC) 2822, which itself superseded Request For Comments (RFC) 822 [...]

Short answer use date -R (and -d @<unix> for the unix timestamp). For example, in my machine just now:

$ date -R
Mon, 11 Sep 2017 20:41:30 +0200
$ date -R -d @1505155314
Mon, 11 Sep 2017 20:41:54 +0200