in reply to Time Convert Question

The timestamp you're parsing doesn't contain timezone information
#!/usr/bin/perl -- use warnings; use strict; use DateTime; use DateTime::TimeZone; use DateTime::Format::MySQL; my @Tzs = ( 'America/Los_Angeles', 'UTC', 'America/New_York', ); my $somewhere_time = "2011-06-09 08:19:12"; # pacific time? my $dt = DateTime::Format::MySQL->parse_datetime($somewhere_time); print $dt->_TZLP; Tzss( $dt ); print ' ' x 21, DateTime::Format::MySQL->format_datetime($dt),"\n\n"; # I should be expecting to get: 2011-06-09 10:19:12 Tzss( DateTime->now ); sub Tzss { my $dt = shift; for my $tz ( @Tzs ) { $dt->set_time_zone( $tz ); print $dt->_TZLP; } } sub DateTime::_TZLP { sprintf "%-20s %s\n", $_[0]->time_zone_long_name, $_[0]->strftime("%F %T%z"); } __END__ floating 2011-06-09 08:19:12+0000 America/Los_Angeles 2011-06-09 08:19:12-0700 UTC 2011-06-09 15:19:12+0000 America/New_York 2011-06-09 11:19:12-0400 2011-06-09 11:19:12 America/Los_Angeles 2011-06-09 09:43:52-0700 UTC 2011-06-09 16:43:52+0000 America/New_York 2011-06-09 12:43:52-0400

Replies are listed 'Best First'.
Re^2: Time Convert Question
by Anonymous Monk on Jun 09, 2011 at 18:27 UTC
    Actually a quick fix to this is to add this line at the beginning of the Perl code:
    $ENV{'TZ'} = 'America/New_York';

    How's that!?
      How's that!?

      What are you hoping to accomplish with that? America/New_York is not pacific time