Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

RFC822 and ISO8601 date formats in Perl

Using only the standard POSIX module.

#!/usr/bin/perl -w

 use strict;
 use POSIX qw(strftime);

 my $now = time();

 # We need to munge the timezone indicator to add a colon between the hour and minute part
 my $tz = strftime("%z", localtime($now));
 $tz =~ s/(\d{2})(\d{2})/$1:$2/;

 # ISO8601
 print strftime("%Y-%m-%dT%H:%M:%S", localtime($now)) . $tz . "\n";
 # RFC822 (actually RFC2822, as the year has 4 digits)
 print strftime("%a, %d %b %Y %H:%M:%S %z", localtime($now)) . "\n";

Create an RFC822 compliant date in Perl

use Date::Manip qw(ParseDate UnixDate);

# Create an RFC822 compliant date (current time)
my $rfc822_format = "%a, %d %b %Y %H:%M %Z";
my $today         = ParseDate("Now");

my $rfc822_date   = UnixDate($today,$rfc822_format);

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS