Jump to content

Timezones


atholon

Recommended Posts

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

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

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

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

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

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

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.