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

RFC822 and ISO8601 date formats in Perl (See related posts)

Using only the standard POSIX module.

   1  
   2  #!/usr/bin/perl -w
   3  
   4   use strict;
   5   use POSIX qw(strftime);
   6  
   7   my $now = time();
   8  
   9   # We need to munge the timezone indicator to add a colon between the hour and minute part
  10   my $tz = strftime("%z", localtime($now));
  11   $tz =~ s/(\d{2})(\d{2})/$1:$2/;
  12  
  13   # ISO8601
  14   print strftime("%Y-%m-%dT%H:%M:%S", localtime($now)) . $tz . "\n";
  15   # RFC822 (actually RFC2822, as the year has 4 digits)
  16   print strftime("%a, %d %b %Y %H:%M:%S %z", localtime($now)) . "\n";

You need to create an account or log in to post comments to this site.


Click here to browse all 5827 code snippets

Related Posts