Skip to content

Instantly share code, notes, and snippets.

@evandhoffman
Created October 27, 2011 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evandhoffman/1320264 to your computer and use it in GitHub Desktop.
Save evandhoffman/1320264 to your computer and use it in GitHub Desktop.
Parse a date in RT format into RFC822
#!/usr/bin/perl
use DateTime;
my $date = '2009-02-13 15:43:14';
print "Original: $date\n";
print "Converted: ";
my ($year, $month, $day, $hour, $minutes, $seconds) =
($date=~ /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/);
my $datetime = DateTime->new(
year => $year,
month => $month,
day => $day,
hour => $hour,
minute => $minutes,
second => $seconds,
time_zone => 'America/New_York',
);
print $datetime->strftime("%a, %d %b %Y %H:%M:%S %z");
print "\n";
exit;
@evandhoffman
Copy link
Author

Output:

Original: 2009-02-13 15:43:14
Converted: Fri, 13 Feb 2009 15:43:14 -0500

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment