Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Make HTTP date usable

by Anonymous Monk
on Sep 17, 2009 at 12:01 UTC ( [id://795864]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

HTTP returns a date as "Last-Modified: Thu, 17 Sep 2009 11:09:02 GMT". LWP's HTTP::Response->header() could be used to get the value, but I really need a timestamp.
Which module is the best for this?

Replies are listed 'Best First'.
Re: Make HTTP date usable
by wfsp (Abbot) on Sep 17, 2009 at 12:09 UTC
    #!/usr/bin/perl use warnings; use strict; use Date::Parse; my $date = q{Thu, 17 Sep 2009 11:09:02 GMT}; my $time = str2time($date); print $time;
    1253185742
Re: Make HTTP date usable
by ccn (Vicar) on Sep 17, 2009 at 12:09 UTC
Re: Make HTTP date usable
by Corion (Patriarch) on Sep 17, 2009 at 12:12 UTC
Re: Make HTTP date usable
by ikegami (Patriarch) on Sep 17, 2009 at 14:30 UTC
    Not it doesn't. ->last_modified returns epoch time (as returned by time).
    >perl -MLWP -E"say LWP::UserAgent->new->get('http://www.perlmonks.org' +)->last_modified" 1253197990

    You can format the result by using localtime or gmtime with POSIX's strftime. Alternatively, every date module out there accepts epoch time as an input.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://795864]
Approved by moritz
Front-paged by tye
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-16 18:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found