Jump to content

php timezone


birbal

Recommended Posts

if i use now() function to store data in mysql datetime field. it will store current date and time of the server. if i want to store user timezone date and time. how should i aproach?

Link to comment
Share on other sites

You'll have you get the user's timezone using JavaScript, then change the timezone in PHP using date_default_timezone_set().

Link to comment
Share on other sites

You'll have you get the user's timezone using JavaScript, then change the timezone in PHP using date_default_timezone_set().
i dont know java script. can you please give some example code and illaborate it or give me any link?i dont know how to pass javascript value to php script.i have another question.........1) will it be better to use unix time stamp rather than datetime() or now() to hadle it better if i want to work with time(store in datbase) by user timezone?
Link to comment
Share on other sites

First you get the time with java script:

<script type="text/javascript">	var gmtOffset = -new Date().getTimezoneOffset()/60;</script>

Then you need to pass that value to PHP using AJAX, then you can use the offset to set the user's timezone in PHP with the function Synook mentioned. There are some useful scripts in the comments of the php.net manual page of that function.

Link to comment
Share on other sites

First you get the time with java script:
<script type="text/javascript">	var gmtOffset = -new Date().getTimezoneOffset()/60;</script>

Then you need to pass that value to PHP using AJAX, then you can use the offset to set the user's timezone in PHP with the function Synook mentioned. There are some useful scripts in the comments of the php.net manual page of that function.

ok thanks a lot. i have to check ajax first now. i dont know ajax. is ajax script can be run from mobile browsers?
Link to comment
Share on other sites

AJAX is not a language, but just a usage model for the JavaScript XMLHttpRequest object. If a mobile browser supports JavaScript properly, it probably implements the XMLHttpRequest object too.http://w3schools.com/ajax/

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...