birbal Posted October 9, 2010 Share Posted October 9, 2010 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 More sharing options...
Synook Posted October 9, 2010 Share Posted October 9, 2010 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 More sharing options...
birbal Posted October 16, 2010 Author Share Posted October 16, 2010 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 More sharing options...
Fmdpa Posted October 16, 2010 Share Posted October 16, 2010 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 More sharing options...
birbal Posted October 17, 2010 Author Share Posted October 17, 2010 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 More sharing options...
Synook Posted October 17, 2010 Share Posted October 17, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.