How can I elegantly print the date in RFC822 format in Perl?
+15
A:
use POSIX qw(strftime);
print strftime("%a, %d %b %Y %H:%M:%S %z", localtime(time())) . "\n";
njsf
2008-10-05 15:12:41
Oh, nice, I didn't know there was something in the core that would do this.
Adam Bellaire
2008-10-05 15:15:14
Thank you ,this is exactly, what I was looking for when I asked for an elegant way :)
Tom Feiner
2008-10-05 15:27:49
+10
A:
The DateTime suite gives you a number of different ways, e.g.:
use DateTime;
print DateTime->now()->strftime("%a, %d %b %Y %H:%M:%S %z");
use DateTime::Format::Mail;
print DateTime::Format::Mail->format_datetime( DateTime->now() );
print DateTime->now( formatter => DateTime::Format::Mail->new() );
Update: to give time for some particular timezone, add a time_zone argument to now():
DateTime->now( time_zone => $ENV{'TZ'}, ... )
ysth
2008-10-05 17:40:51