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]
[Corion]: Oof - "Anyway, if it is not obvious, please keep this discussion entirely confidential for now.", as seen on a public mailing list ;)
[Discipulus]: uh no choroba.. i do not practice much with online putyour image sites:can you suggest one (that possibly remove the pic after few days)?
[choroba]: Corion a bug report?
[choroba]: I have no idea :-( I used to post to, but they don't seem to feature "private" pictures in the free version now
[Discipulus]: dazz i'm not an experts but i think it would be possible
[Corion]: dazz: I think Image::Magick can "read" from an in-memory filehandle
[Corion]: choroba: No, some general admin discussion of how to handle (company) user accounts
[Discipulus]: might be it is necessary to pass the pic data like MIME::Base64:: encode( data..

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2017-03-27 07:50 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (317 votes). Check out past polls.