Converting Time/Date into epoch string

Hello all I have a file that I am parsing with a time/date in the
format of:

Mon May 14 10:19:46 EDT 2007

I want to take this and turn that into epoch does anyone have a good
way to do this quickly?


Thanks,
-Steve
sunadmn [ Fr, 01 Juni 2007 20:42 ] [ ID #1728209 ]

Re: Converting Time/Date into epoch string

On 06/01/2007 01:42 PM, sunadmn wrote:
> Hello all I have a file that I am parsing with a time/date in the
> format of:
>
> Mon May 14 10:19:46 EDT 2007
>
> I want to take this and turn that into epoch does anyone have a good
> way to do this quickly?
>
>
> Thanks,
> -Steve
>

use Date::Parse;
my $time = str2time('Mon May 14 10:19:46 EDT 2007');

You'd have to install the Date::Parse module first. It can be found on
CPAN and as part of some Linux distributions.
paduille.4061.mumia.w [ Fr, 01 Juni 2007 21:28 ] [ ID #1728210 ]

Re: Converting Time/Date into epoch string

On Jun 1, 2:42 pm, sunadmn <suna... [at] gmail.com> wrote:
> Hello all I have a file that I am parsing with a time/date in the
> format of:
>
> Mon May 14 10:19:46 EDT 2007
>
> I want to take this and turn that into epoch does anyone have a good
> way to do this quickly?

Download the Date::Parse module from CPAN.
http://search.cpan.org/~gbarr/TimeDate-1.16/lib/Date/Parse.p m

$ perl -MDate::Parse -le'print str2time("Mon May 14 10:19:46 EDT
2007");'
1179152386

Paul Lalli
Paul Lalli [ Fr, 01 Juni 2007 21:28 ] [ ID #1728211 ]

Re: Converting Time/Date into epoch string

On Jun 1, 3:28 pm, "Mumia W." <paduille.4061.mumia.w
+nos... [at] earthlink.net> wrote:
> On 06/01/2007 01:42 PM, sunadmn wrote:
>
> > Hello all I have a file that I am parsing with a time/date in the
> > format of:
>
> > Mon May 14 10:19:46 EDT 2007
>
> > I want to take this and turn that into epoch does anyone have a good
> > way to do this quickly?
>
> > Thanks,
> > -Steve
>
> use Date::Parse;
> my $time = str2time('Mon May 14 10:19:46 EDT 2007');
>
> You'd have to install the Date::Parse module first. It can be found on
> CPAN and as part of some Linux distributions.

Thank you all I knew it had to be simple.

-Steve
sunadmn [ Fr, 01 Juni 2007 21:44 ] [ ID #1728212 ]

Re: Converting Time/Date into epoch string

On 06/01/2007 02:44 PM, sunadmn wrote:
> On Jun 1, 3:28 pm, "Mumia W." <paduille.4061.mumia.w
> +nos... [at] earthlink.net> wrote:
>> use Date::Parse;
>> my $time = str2time('Mon May 14 10:19:46 EDT 2007');
>>
>> You'd have to install the Date::Parse module first. It can be found on
>> CPAN and as part of some Linux distributions.
>
> Thank you all I knew it had to be simple.
>
> -Steve
>

You're welcome.

You can search for modules like this on CPAN's site:
http://search.cpan.org/
paduille.4061.mumia.w [ Fr, 01 Juni 2007 23:27 ] [ ID #1728213 ]

Re: Converting Time/Date into epoch string

Date::Manip module works very good for these kind of operations.

Check it out on CPAN.

my $start_date = "Mon May 14 10:19:46 EDT 2007" ; ( your input )

Something like the following should do what you want.

ParseDate($start_time);
my [at] FORMATS = ( "%s" ) ;
my $sec_start = UnixDate( $start_date, [at] FORMATS ) ;

Regards.
Asim Suter


"sunadmn" <sunadmn [at] gmail.com> wrote in message
news:1180723356.048260.263600 [at] m36g2000hse.googlegroups.com.. .
> Hello all I have a file that I am parsing with a time/date in the
> format of:
>
> Mon May 14 10:19:46 EDT 2007
>
> I want to take this and turn that into epoch does anyone have a good
> way to do this quickly?
>
>
> Thanks,
> -Steve
>
Asim Suter [ Mi, 20 Juni 2007 22:33 ] [ ID #1744267 ]
Perl » alt.perl » Converting Time/Date into epoch string

Vorheriges Thema: Create Unique Message-ID
Nächstes Thema: possible ActivePerl substitution optimisation issue