There are a bunch of modules to do Date/Time calculations. If you want to use a relatively low level module that will be installed, then something like this can be done:
#!/usr/bin/perl use strict; use warnings; use Time::Local; # $time = timelocal( $sec, $min, $hour, $mday, $mon, $year ); # $time = timegm( $sec, $min, $hour, $mday, $mon, $year ); my %nMonth = (Jan=>0, Feb=>1, Mar=>2, Apr=>3, May=>4, Jun=>5, Jul=>6, Aug=>7, Sep=>8, Oct=>9, Nov=>10, Dec=>11); foreach my $date ('Fri Jul 15 08:02:02 2016') { my ($textMonth,$day,$hour,$min,$sec,$year) = $date =~ /^\w+\s+(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)/; print "parsed results= $textMonth,$day,$hour,$min,$sec,$year\n"; my $localSecs = timelocal($sec, $min, $hour, $day, $nMonth{$textMont +h}, $year); print "localsecs = $localSecs\n"; my $gmSecs = timegm($sec, $min, $hour, $day, $nMonth{$textMonth}, $y +ear); print "gmsecs = $gmSecs\n"; } __END__ parsed results= Jul,15,08,02,02,2016 localsecs = 1468594922 gmsecs = 1468569722 (1468569722-1468594922)/60/60=-7 hours Correct for PSDT(my curent time + zone)
Update: This simple code above has limitations. What happens if you want to convert a local time that occurred say in "winter time" vs current "summer time"? Something more sophisticated is needed. Perhaps the Date::Time module.

In reply to Re: Convert Date to Epoch seconds by Marshall
in thread Convert Date to Epoch seconds by vit

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.