0

I have a php script which gives server time, but as per knowledge, we can get the user's machine time and time zone with the help of client side scripts (javascript). I have mysql table which has dates stored along with timezone from where it was stored with the help of form. I need to show the data on a web page along with the time stored in the table, but it should be per user's machine.

rowid | date | timezone | data |
----------------------------------
12  | 2010-07-13 12:30:00 | Asia/Kolkata | This is data field |
143 | 2010-07-13 12:30:00 | Europe/Prague | This is data field |

Now, when I show date on web page, I need to show the above date per user's machine timezone.

A workaround logic would be that, if I could pass the date (2010-07-13 12:30:00) to some JS method which will take two time zone as input and convert the given date into user's machine's timezone. Or Something else?

Please help?

SachinKRaj
  • 183
  • 2
  • 18
  • So I suppose a PHP solution is out of the question? – Artefacto Jul 13 '10 at 11:25
  • *(related)* [Timezone Conversion in PHP](http://stackoverflow.com/questions/2505681/timezone-conversion-in-php/2505687#2505687) - in case you decide not to do it on the client side. – Gordon Jul 13 '10 at 11:32

1 Answers1

0

See the following link:

http://us3.php.net/manual/en/function.date-timezone-set.php

You can set the timezone in the script before displaying the dates although make sure you insert all the times in the DB as GMT.

Wright-Geek
  • 385
  • 2
  • 5
  • 11
  • How do I get visitor's timezone with php? It can be done with javascript only I think? – SachinKRaj Jul 15 '10 at 06:00
  • Sorry for the delay, the best way is to use javascript and then maybe have an ajax function push it to a session var. I have managed to do this many years ago with PHP using their IP Address and getting the details of that but was a huge headache – Wright-Geek Jul 16 '10 at 12:39