Page 1 of 1

How do I display the visitor's local time?

Posted: Sat Jun 28, 2008 5:48 am
by wwmmww
Right now I have this code on my site

Code: Select all

 
<?php
echo date("l \\t\h\e jS \o" . "f" . " F, g:i a");
?>
 
But it only shows the server time and not the visitor's

How can I do this?


Thanks!

Re: How do I display the visitor's local time?

Posted: Sat Jun 28, 2008 8:17 am
by onion2k
It can't be done with PHP. There's nothing communicated from the user's computer to the server to tell you their time or timezone. You can do it with Javascript, but that's a bit of a hassle and it won't work if the user has Javascript switched off.

Re: How do I display the visitor's local time?

Posted: Sat Jun 28, 2008 10:21 am
by Eran
You will have to know the user's timezone to do this. If you have the timezone you can set it using date_default_timezone_set() - http://www.php.net/manual/en/function.d ... ne-set.php, and the the date function will format it accordingly.

Re: How do I display the visitor's local time?

Posted: Sun Jun 29, 2008 7:35 am
by jmut
pytrin wrote:You will have to know the user's timezone to do this. If you have the timezone you can set it using date_default_timezone_set() - http://www.php.net/manual/en/function.d ... ne-set.php, and the the date function will format it accordingly.
@wwmmww In that regard.... it's usual practice to let customer set their timezone on registering and/or configure it whenever they want.... cause other means are just unreliable.

Re: How do I display the visitor's local time?

Posted: Sun Jun 29, 2008 8:33 am
by Eran
thats what i meant.. they have to set it in their profile / session whatever and in the php you enforce it using the function i mentioned. You don't expect that just setting it in the profile will have any effect?