Friday, April 27, 2007

Local date and time

When I store the present date and time on the server what is stored is the server's (in Hong Kong, California, ...) local date and time.

However, I want the user to see the local date and time where he is located when the data is extracted from the server's database.

With javascript one may find the local offset. To feed that information back into a php file can be done as shown below.

A page is called with $arg arguments, if the local offset has not been already calculated (if (!isset($p_offset))) then write a javascript that will run and call the page itself (location.href = ...) with the arguments as before plus one more argument called offset.
















To try the code, click http://iwantyourquestion.com/test.php?abc=2&def=cat

The seond part takes place when you extract datetime information from the server stored in its local time.














To try the code, click http://iwantyourquestion.com/test2.php

No comments: