atholon Posted December 8, 2007 Share Posted December 8, 2007 Hi, I want to make a script that gets the server date and time and inputs it into a sql table then when the user goes onto the site it interprets it to the current time zone on the user's computer. What would be the easiest way to go about doing this? I believe it would be a mixture of JS with PHP but I am not sure how you could interpret the php to the JS Link to comment https://forums.phpfreaks.com/topic/80792-timezones/ Share on other sites More sharing options...
dbo Posted December 8, 2007 Share Posted December 8, 2007 I'm not sure that you need the PHP at all. Can you explain a little bit more about what you're trying to do? Link to comment https://forums.phpfreaks.com/topic/80792-timezones/#findComment-409803 Share on other sites More sharing options...
atholon Posted December 8, 2007 Author Share Posted December 8, 2007 I for example I am going to make a news script for my site. I want to make it so that when the user submits the news article...when all the other information is being submitted....it also would place the date and current time which would be UTC (I guess) then when the user is looking at the article the Sql query would be displayed but the JS would convert and display the time in the current time zone for the browser the member is using. Link to comment https://forums.phpfreaks.com/topic/80792-timezones/#findComment-409810 Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 Set a Timezone column in the DB for the user, then just subtract/add based on that to display the local time. Link to comment https://forums.phpfreaks.com/topic/80792-timezones/#findComment-409811 Share on other sites More sharing options...
mr_mind Posted December 8, 2007 Share Posted December 8, 2007 I would assume that it is all php. i would just figure out how to find the UTC offset on the users computer (maybe through a form setting) and then based on that in the while statement which generates whatever data you are generating edit the time value which is coming from the database Link to comment https://forums.phpfreaks.com/topic/80792-timezones/#findComment-409813 Share on other sites More sharing options...
atholon Posted December 8, 2007 Author Share Posted December 8, 2007 thing is that it is for guests and they won`t be logged in to have the time zone column. ntm I don`t think that PHP can get the user's time zone info from the browser. Link to comment https://forums.phpfreaks.com/topic/80792-timezones/#findComment-409815 Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 Nope, you need to get it another way. thing is that it is for guests and they won`t be logged in to have the time zone column. ntm I don`t think that PHP can get the user's time zone info from the browser. Link to comment https://forums.phpfreaks.com/topic/80792-timezones/#findComment-409816 Share on other sites More sharing options...
atholon Posted December 8, 2007 Author Share Posted December 8, 2007 I will just have to see how to do that in J script I don't think that it would be that complicated. I was just wondering if there was a quick solution. Should be a common thing to do on most sites. I might have to edit the PHP string to conform with Js's timezoneoffset function. Link to comment https://forums.phpfreaks.com/topic/80792-timezones/#findComment-409818 Share on other sites More sharing options...
dbo Posted December 8, 2007 Share Posted December 8, 2007 I don't see the value that this adds. Doesn't sound like it's worth the effort to me. But yes it can get it from the browser. You'll create a hidden form variable for their time zone. Then set its value after you determine it from javascript. If javascript disabled and the value remans "" then default it to whatever time zone you think makes sense. Link to comment https://forums.phpfreaks.com/topic/80792-timezones/#findComment-409819 Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 Most sites I go to dont bother to convert time for guests. Link to comment https://forums.phpfreaks.com/topic/80792-timezones/#findComment-409820 Share on other sites More sharing options...
atholon Posted December 8, 2007 Author Share Posted December 8, 2007 if you do it that way then the user will have it recorded in HIS time zone. I need it to display for other timezones of guests. The form method woul`nt be accurate. Link to comment https://forums.phpfreaks.com/topic/80792-timezones/#findComment-409822 Share on other sites More sharing options...
dbo Posted December 8, 2007 Share Posted December 8, 2007 You would just do a hidden field: <input type="hidden" id="timezone" name="timezone" value="" /> then on down you'd determine the timezone based on javascript <script type="text/javascript"> function getTimezone() //No idea what the code looks like to do this... but it should be easy { } document.getElementById('timezone').value = getTimeZone(); </script> Then when you post your form back you would get the timezone out of $_POST['timezone'] Link to comment https://forums.phpfreaks.com/topic/80792-timezones/#findComment-409824 Share on other sites More sharing options...
atholon Posted December 8, 2007 Author Share Posted December 8, 2007 Yes but as you see that posts it correctly for him. But....the timezone wouldn`t be of any good for other users. It would be better to post in UTC. Link to comment https://forums.phpfreaks.com/topic/80792-timezones/#findComment-409827 Share on other sites More sharing options...
dbo Posted December 8, 2007 Share Posted December 8, 2007 It's the exact same principle in reverse.... when you render the form you set the field to the timezone.... then you determine the end users timezone and adjust it accordingly. Link to comment https://forums.phpfreaks.com/topic/80792-timezones/#findComment-409829 Share on other sites More sharing options...
atholon Posted December 8, 2007 Author Share Posted December 8, 2007 yah but that is posting permanent data in the poster's time zone. If I did it the way I am trying to it would interpret the UTC or server time that it was posted and change it to the correct. the form method would leave it as the poster's timezone info Link to comment https://forums.phpfreaks.com/topic/80792-timezones/#findComment-409831 Share on other sites More sharing options...
dbo Posted December 9, 2007 Share Posted December 9, 2007 If you know the that it was posted at 1:00am server time... and you know the server time is timezone x.... and you can determine the user's timezone using javascript, you can absolutely do the conversion. Link to comment https://forums.phpfreaks.com/topic/80792-timezones/#findComment-410063 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.