Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Website Date

by sauoq (Abbot)
on May 16, 2012 at 23:36 UTC ( #970950=note: print w/replies, xml ) Need Help??

in reply to Website Date

I was thinking I might be able to get the header from the URL, and that should have the date/time, but that seems very clumsy and it seems like there should be a better way.

If you are using WWW::Mechanize anyway, why not? The server tells you the date with every response. Try something like:

$date = $mech->response()->header("Date");
You'll probably want to use either Date::Parse or Time::ParseDate to do something useful with it after you get it.

Update: I should mention that trying to do something at a precise time based on a time you retrieve from a remote server is really tricky. One second isn't very precise but, especially as the time you'll get from the server will probably only be reported with a granularity of one second, it'll be tough to get that exact.

Edit: Changed "request" to "response" for correctness.

"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re^2: Website Date
by gsparx (Novice) on May 16, 2012 at 23:49 UTC

    Well that worked a treat. I think if I make it within 5 seconds it will work ok. Now I just have to figure out if it's really the website's server that determines the time or if it's something else. Thanks for your help.

      Now I just have to figure out if it's really the website's server that determines the time or if it's something else.

      The Date header is set by the webserver, but it may have been changed by any proxy between the webserver and the client. Usually, proxies do not touch the date header, simply because there is no need. The webserver usually just asks the operating system for its idea of the current time, because that's the easiest way to implement it. So, when you request any webserver and read the Date header from the response, you will most times see the operating system's idea of the current time, plus some fractions of a second for transport through the networks.

      The only notable exceptions are embedded systems without the need for time keeping and thus without any reliable time source, they either omit the Date header or send some nonsense, like 1970-01-01 00:00:00 + uptime.


      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://970950]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2018-06-22 23:52 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.