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

This is a question about time. (not localtime(), though)
How can I get the current time in a certain place?
Say I wanted to get the current date of the month from Greenwich Mean Time - 7 hours?
This is such a dumb kind of question, but I need it for my site!
What I need it do do is every time the first section of my LONG script is run, it checks the date stored in a file.
If the date in the file does not match the current date, a certain file is deleted from my site. Then the current date is stored in that date file.
What this gives me is that every day, that one file is deleted.
BUT my problem now is that when using localtime(), the date can be different for different users, depending where in the world they are located!
So now I want to get the time for a specific time zone, then it will be the "same" date for all users. Thanx.

Wheh, a lot of typing! :-D

Replies are listed 'Best First'.
Re: Time Question
by reptile (Monk) on May 08, 2000 at 18:25 UTC

    I'm not sure I completely understand your problem, but check out perlfunc:gmtime. It's just like perlfunc:localtime, but uses GMT.

    72656B636148206C72655020726568746F6E41207473754A

RE: Time Question
by merlyn (Sage) on May 08, 2000 at 23:02 UTC
Re: Time Question
by Maqs (Deacon) on May 08, 2000 at 18:39 UTC
    First of all I'm not sure that foreign users running your script
    will get different values of time. The script is running on your
    machine and must operate with your time settings.
    Yep, you need to look through the descriptions of gmtime/localtime
    functions. But, by all means you can easely use a system date
    function (i.e. $mydate=`date`;) pay attention to backticks.
    --
    With best regards
    Maqs.
RE: Time Question
by Anonymous Monk on May 08, 2000 at 19:11 UTC
    Hello,

    Since it has to be the local time from the clien-computer, you can use javascript to put get the time in a variable that goes to your cgi.
    May be a META refresh to retrieve them or a hidden tag in a form...
Re: Time Question
by athomason (Curate) on May 08, 2000 at 20:01 UTC
    You need to devise a way for your server to determine what timezone the client is in. I once saw a site that claimed to somehow determine this from IP address alone (I don't know with how much accuracy), but the source wasn't available for it :(. JavaScript would be easiest, though somewhat of a kludge, because you would need two pageloads to get the timezone info back. An embedded Java app (blech) is another highly unrecommended approach, but it would take only one load.

    An offhand idea: does anybody know if local times can be coerced from the client when it sends a cookie value back? I don't know of any such way, but if so, you could pull some magic by sending a cookie with the main page and then getting it back with a graphic on that page.

A reply falls below the community's threshold of quality. You may see it by logging in.