Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9005183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:04:40+00:00 2026-06-16T01:04:40+00:00

I have 2 linux machines that need to run a perl script and access

  • 0

I have 2 linux machines that need to run a perl script and access a database.
For any reason, date itself is correct, but returning epoch from Perl has 1 hour difference resulting in having on one machine UTC epoch-timestamp and on the other the wanted CET.

date on A:

Tue Dec 11 13:34:09 CET 2012

date on B:

Tue Dec 11 13:33:20 CET 2012

To check whats going on I build a minimalistic example.
The script uses Time::HiRes and gathering the localtime->epoch to generate a date.
I build a minimalistic following script to output the behaviour:

#/usr/bin/perl
#
use Time::HiRes qw(time);
use Time::Piece;
#
my $date = Time::Piece->strptime(localtime->epoch,"%s");
print "$date->datetime"."\n";
print $date->tzoffset."\n";
print $date->epoch."\n";

Output Machine A:

Tue Dec 11 12:35:43 2012->datetime
0
1355229343

Output Machine B:

Tue Dec 11 13:34:25 2012->datetime
0
1355232865

So as you see something must be wrong with timezone or so. The differ with an hour. But I don’t know where to look and what to configure as date itself outputs the correct time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:04:41+00:00Added an answer on June 16, 2026 at 1:04 am

    This seems to be a bug in Time::Piece->strptime(STRING, FORMAT). Here is the code in question:

    sub strptime {
        my $time = shift;
        my $string = shift;
        my $format = @_ ? shift(@_) : "%a, %d %b %Y %H:%M:%S %Z";
        my @vals = _strptime($string, $format);
    

    Let’s start here. _strptime is the operating system’s native strptime function. It appears to return local time, although that’s not documented anywhere.

    #    warn(sprintf("got vals: %d-%d-%d %d:%d:%d\n", reverse(@vals)));
        return scalar $time->_mktime(\@vals, (ref($time) ? $time->[c_islocal] : 0));
    

    Okay, so we use our _mktime method to turn the output of _strptime into a Time::Piece object. The second parameter is whether _mktime should interpret as local time or UTC. When called as Time::Piece->strptime(STRING, FORMAT), ref($time) will be false, and so _mktime will be called with $islocal=0, i.e. that _strptime returned a UTC time. This is wrong, and we’ve found the bug. (I don’t know enough about the C time functions to know how it should be done.)

    }
    

    So you have to use localtime->strptime(STRING, FORMAT). Except this will still fail on old versions of the module due to another bug in _mktime (my distribution comes with version 1.15 where this is still broken, but it’s fixed in 1.20).

    It’s not even a strange issue specific to %s. It happens for any Time::Piece->strptime call:

    $ perl -MTime::Piece -E'say $x=Time::Piece->strptime("11 Dec 2012 10:00","%d %b %Y %H:%M")->epoch;say scalar localtime $x'
    1355220000
    Tue Dec 11 04:00:00 2012
    $ perl -MTime::Piece -E'say $x=localtime->strptime("11 Dec 2012 10:00","%d %b %Y %H:%M")->epoch;say scalar localtime $x'
    1355220000
    Tue Dec 11 04:00:00 2012
    $ export PERL5LIB=Time-Piece-1.20/blib/lib:Time-Piece-1.20/blib/arch
    $ perl -MTime::Piece -E'say $x=Time::Piece->strptime("11 Dec 2012 10:00","%d %b %Y %H:%M")->epoch;say scalar localtime $x'
    1355220000
    Tue Dec 11 04:00:00 2012
    $ perl -MTime::Piece -E'say $x=localtime->strptime("11 Dec 2012 10:00","%d %b %Y %H:%M")->epoch;say scalar localtime $x'
    1355241600
    Tue Dec 11 10:00:00 2012
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python script that can run anywhere from 10 seconds to 5
I need a script that automatically makes a backup of a MySql Database. I
I have a Powershell script that is going to be run through an automation
I have some files which need to be sftp from machine B ( linux
I have a linux C program that handles request sent to a TCP socket
I need to run a PHP CLI script and give it a LOT of
I have heard that setting the --prefix=PREFIX option when compiling PHP on linux will
I have a Python script that I'd like to compile into a Windows executable.
I need to run Java applications on top of Linux on my Beaglebone. I
have you struggled with Linux deployment before? I need to deploy an application into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.