[LA.pm] time conversion question
William Yardley
lapm at veggiechinese.net
Thu Jul 27 21:31:50 PDT 2006
On Thu, Jul 27, 2006 at 04:42:21PM -0700, Peter Scott wrote:
> 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
> [...]
> > (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));
After messing with it a little and looking at TFM, looks like that
should be:
strftime('%Y-%m-%d %H:%M:%S', localtime(str2time($date)));
It does seem faster (even on a single calculation) and a bit more robust
at dealing with comments.
w
More information about the Losangeles-pm
mailing list