Get Users Local Time

They have: 359 posts

Joined: Mar 1999

There must be 10 ways to get server time in php3, but can't figure out how to get the users local machine time. Is this possible with php3. All I need is the first # of an international/military time. (i.e 1PM = 13)

I want it so depending on the time of day, will display a different message like Good Morning, Afternoon, etc.
Currently using
$time = date("G");
if($time >=0 && $time < 12){
echo ("Good Morning");
}
which works, but this is server time which is CDT and if somebody is in any other time zone, wouldn't be correct all the time.

Any help will be appreciated,

Dan
Recycle Video Games Network

Stupidity killed the cat, curiosity was framed!

They have: 359 posts

Joined: Mar 1999

Was reading an article on PHP Builder and think I have answered my own question. PHP is server side and so never sees the client computer. Thus, would have to use JS to do what I want to do.

Course that brings up the question, Can I use a JS variable and port it to php?

Dan
Recycle Video Games Network

Stupidity killed the cat, curiosity was framed!

merlin's picture

They have: 410 posts

Joined: Oct 1999

Quote: Originally posted by cds
Course that brings up the question, Can I use a JS variable and port it to php?

i don't know php. but probably with a hidden form-field? just a guess... let me know

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

try this:

Using .htaccess, make "get_time.html" your start page.
Then, use JS to grab the time, and redirect to "index.php?hour=XX&minute=XX".
You can now compare the local time to server time.

I recommend storing that in a session var or cookie, then you can use it as long as they are still on the site without having to pass it through every link.

I passed hour and minute in my example, becase if the clients clock is off by a few minutes, and they acces your page near the top of the hour... their clock may say 11:58, and your server say 12:02. I suppose you could even take it to the extreme and say: "What if it's new years eve, and the client's clock is 12/31/01 23:58:00 and the server is 01/01/02 01:02:00?"

Mark Hensler
If there is no answer on Google, then there is no question.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.