[LA.pm] time conversion question

William Yardley lapm at veggiechinese.net
Wed Jul 26 22:30:00 PDT 2006


I have a question about converting times... if I have a timestamp like
the one on an email message:

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

(etc.)
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
converting to a GMT epoch timestamp and back to localtime in "normal"
format?

so far, I have something like:

use Time::Local;
my (undef,$day,$mon,$year,$time,$offset)  = split(/\s+/,$report->get('arrival-date'));
my ($hour,$min,$sec) = split(/:/,$time);
# maybe needless to convert to epoch and back, but I can't
# think of a better way to do it
my $gmtime = timegm($sec,$min,$hour,$day,$mon,$year);
# is this right?
$gmtime += (($offset/100)*60*60);

then convert back and format...

Is there something that will do what I want for me?

w



More information about the Losangeles-pm mailing list