Normally, with Time::Piece, you would use the strptime() method to parse a date and generate a new Time::Piece object from which you can get the seconds using epoch(). However, it does not appear to handle huge dates.

Here's the Date::Manip way, which handles rarified dates nicely, from the docs:

NOTE: One of the most frequently asked questions that I have gotten is how to parse seconds since the epoch. ParseDateString cannot simply parse a number as the seconds since the epoch (it conflicts with some ISO-8601 date formats). There are two ways to get this information. First, you can do the following:
$secs = ... # seconds since Jan 1, 1970 00:00:00 GMT $date = &DateCalc("Jan 1, 1970 00:00:00 GMT",$secs);
Second, you can call it directly as:
$date = &ParseDateString("epoch $secs");
To go backwards, just use the "%s" format of UnixDate:
$secs = &UnixDate($date,"%s");

Also from the docs, the section pertaining to far-flung dates and the algorithm:

Date::Manip deals with time as it is presented the Gregorian calendar (the one currently in use). The Julian calendar defined leap years as every 4th year. The Gregorian calendar improved this by making every 100th year NOT a leap year, unless it was also the 400th year. The Gregorian calendar has been extrapolated back to the year 0000 AD and forward to the year 9999 AD. Note that in historical context, the Julian calendar was in use until 1582 when the Gregorian calendar was adopted by the Catholic church. Protestant countries did not accept it until later; Germany and Netherlands in 1698, British Empire in 1752, Russia in 1918. Note that the Gregorian calendar is itself imperfect and at some point will need to be corrected. No attempt is made to correct for that, and my great great great grandchildren will be long dead before this even occurs, so it's not an immediate concern. Yes, this is the same type of attitute that caused the great Y2K problem... but I have an excuse: I don't know what the correction will be, so I can't possible implement it. Nobody doubted that the year after 1999 would be known as 2000 :-).

Hope that helps.
Matt


In reply to Re: Converting dates later than 2038 into epochseconds by mojotoad
in thread Converting dates later than 2038 into epochseconds by strat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.