[LA.pm] time conversion question

Peter Scott Peter at psdt.com
Thu Jul 27 16:42:21 PDT 2006


At 11:26 PM -0700 7/26/06, Eric Hammond wrote:
>William Yardley wrote:
>>  is there an efficient / simple way to normalize this to (my) localtime
>>  in a format for a MySQL timestamp (0000-00-00 00:00:00) without
>
>"Efficient" is relative.  Here's simple:
>
>   #!/usr/bin/perl -w
>   use strict;
>   use Date::Manip;
>   while ( my $sometime = <DATA> ) {
>     my $datetime = UnixDate(ParseDateString($sometime), '%Y-%m-%d %H:%M:%S');
>     print "$datetime <= $sometime";
>   }
[...]
>(I don't know anybody who calls Date::Manip efficient except in
>terms of programmer resources, but it sure is convenient.)

I use Date::Parse, which is more lightweight than Date::Manip, and 
then use strftime for the reformatting.  Just TMTOWTDI:

use Date::Parse;
use POSIX qw(strftime);
# ...
my $datetime = strftime('%Y-%m-%d %H:%M:%S', str2time($sometime));


More information about the Losangeles-pm mailing list