Datestamp:

Jul 9 2009 11:55 PM

how can I convert it to epoch?

I know of several ways: str2time() and DateTime (I'm sure there are many other ways but these are the two I usually use). Both of these 2 ways don't work for me.

str2time doesn't work because I'm not able to pass a timezone to it (look in the BUGS section at the bottom of the page):

http://search.cpan.org/~rse/lcwa-1.0.0/lib/lwp/lib/HTTP/Date.pm

Passing in digits, like "-0900" for instance, does not work for me because daylight savings time will screw it up each time (digits will change so somebody will need to modify the script.. this needs to be avoided)

DateTime doesn't work because I can't construct an AM/PM time in there, it can only handle military time.

I'm looking for something like str2time() but it needs to be able to parse that date format (str2time knows a LOT of date formats) AND accept a standard UNIX timezone like "Asia/Tokyo" or "America/New_York" or whatever.

Any suggestions?

UPDATE: It just occured to me that I can construct a hash, something like:

my %mil_time = (); $mil_time{ 1 } = "13" $mil_time{ 2 } = "14" $mil_time{ 3 } = "15" ...

and then I can beat the date format into submission and have it work with DateTime by checking if the datestamp is PM, and if it is, replace the hour with the key's value from %mil_time.

Hm. This would be a lot of typing. :) Still looking for suggestions / comments / whatever.


In reply to Datestamps/epochs and other fun stuff by vxp

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.