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
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
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
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
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
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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.