Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

bash

rfc822

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?

like image 931
Robert C. Holland Avatar asked Oct 30 '25 15:10

Robert C. Holland


1 Answers

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    
like image 185
rodrigo Avatar answered Nov 02 '25 06:11

rodrigo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!