in reply to Converting local time to UTC mystery

With DateTime:
$ use DateTime::Format::Strptime $ DateTime::Format::Strptime->new(pattern => '%Y%m%d %H%M%S', time_zon +e => '+0200',) $DateTime_Format_Strptime1 = DateTime::Format::Strptime=HASH(0x2ce6490 +); $ DateTime::Format::Strptime->new(pattern => '%Y%m%d %H%M%S', time_zon +e => '+0200',)->parse_datetime('20110905 142631') 2011-09-05T14:26:31 $ DateTime::Format::Strptime->new(pattern => '%Y%m%d %H%M%S', time_zon +e => '+0200',)->parse_datetime('20110905 142631')->epoch 1315225591

Replies are listed 'Best First'.
Re^2: Converting local time to UTC mystery
by rovf (Priest) on Sep 05, 2011 at 13:41 UTC
    This hard-codes the timezone (+0200). I happen to know that it is two hours off, but in general, the program can run in any local timezone, so I would need to find out how much I am away from UTC.

    In addition, I would strongly prefer a solution which does not involve DateTime. In my case, parsing the string is easy enought that it can be done by HTTP::Date, so the only problem left is the timezone issue. So, is there an easy way to find out the time difference? Somehow Perl must already "know" this (otherwise, it would not be able to implement gmtime and localtime correctly, doesn't it?)

    -- 
    Ronald Fischer <ynnor@mm.st>

      I would need to find out how much I am away from UTC.

      ...which changes during the year, making it that much more difficult. Yeah, hardcoding offsets is not the way to go.

        That said, '+0200' can be replaced with 'local'