Re: How to convert timestamp to epoch?



On Oct 30, 2:45 pm, "void.no.spam....@xxxxxxxxx"
<void.no.spam....@xxxxxxxxx> wrote:
If I get timestamps in the following format:

22-OCT-07 06.16.44.160000 PM
22-OCT-07 08.16.02.686000 AM

What is the easiest way for me to convert it into the number of
seconds since 1970?

If you convert those first two periods to colons, Date::Parse can
handle it just fine:

#!/usr/bin/perl
use strict;
use warnings;
use Date::Parse 'str2time';
my $date = "22-OCT-07 06.16.44.160000 PM";
$date =~ s/\./:/ for 1..2;
my $epoch = str2time($date);
print "Epoch: $epoch\n";
__END__

Paul Lalli

.



Relevant Pages

  • Re: using range gives warning
    ... "Paul Lalli" wrote in message ... > use strict; ... > use warnings; ... > my @foo; ...
    (comp.lang.perl.misc)
  • Re: can someone help?
    ... "Roll" wrote in message ... > use warnings; ... > use strict; ... Paul Lalli ...
    (comp.lang.perl.misc)
  • Re: Join lines
    ... use strict; ... use warnings; ... chomp $line; ... Paul Lalli ...
    (comp.lang.perl.misc)
  • Re: write/read to/from file problem
    ... Paul Lalli wrote: ... use strict; ... use warnings; ... open (MYFILE, 'data.txt'); ...
    (perl.beginners)
  • Passing value to another CGI.
    ... Paul Lalli wrote: ... > use strict; ... > use warnings; ... > use CGI; ...
    (comp.lang.perl.misc)