I'm using the DateTime Perl module to get the time in a particular timezone. The result of the time is as follows
2010-09-24T02:18:52
How can I convert this to HTTP format before printing?
I'm using the DateTime Perl module to get the time in a particular timezone. The result of the time is as follows
2010-09-24T02:18:52
How can I convert this to HTTP format before printing?
CPAN has what you need: DateTime::Format::HTTP.
Description:
This module provides functions that deal [with] the date formats used by the HTTP protocol (and then some more).
Synopsis:
use DateTime::Format::HTTP;
my $class = 'DateTime::Format::HTTP';
$string = $class->format_datetime($dt); # Format as GMT ASCII time
$time = $class->parse_datetime($string); # convert ASCII date to machine time
Update
You can pass in the timezone of your source data, use DateTime set_time_zone() to change the timezone, and then use strftime to generate the string in 'HTTP' format. For example:
my $dt = DateTime::Format::HTTP->parse_datetime( '2010-03-09T12:34:56', 'EST' );
warn $class->format_datetime( $dt );
warn $dt->strftime( "%a, %d %b %Y %H:%M:%S %Z" );
$dt->set_time_zone( 'CET' );
warn $dt->strftime( "%a, %d %b %Y %H:%M:%S %Z" );
Tue, 09 Mar 2010 17:34:56 GMT
Tue, 09 Mar 2010 12:34:56 EST
Tue, 09 Mar 2010 18:34:56 CET
(line numbers deleted for clarity.)