[LA.pm] time conversion question

Eric Hammond ehammond at thinksome.com
Wed Jul 26 23:26:06 PDT 2006


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";
  }
  __DATA__
  Mon, 24 Jul 2006 14:28:24 -0500 (CDT)
  Mon, 24 Jul 2006 15:28:41 -0400 (EDT)
  Mon, 24 Jul 2006 12:28:28 -0700

Output (in a US Pacific time zone):

  2006-07-24 12:28:24 <= Mon, 24 Jul 2006 14:28:24 -0500 (CDT)
  2006-07-24 12:28:41 <= Mon, 24 Jul 2006 15:28:41 -0400 (EDT)
  2006-07-24 12:28:28 <= Mon, 24 Jul 2006 12:28:28 -0700

The two lines you care about are:
  use Date::Manip;
  UnixDate(ParseDateString(...), '%Y-%m-%d %H:%M:%S')

(I don't know anybody who calls Date::Manip efficient except in
terms of programmer resources, but it sure is convenient.)

--
Eric Hammond
ehammond at thinksome.com


More information about the Losangeles-pm mailing list