Hey everyone currently my server runs on US EST time.
It just came to me that When posting it will always show EST time.
How can I go by showing the correct timezone results for the user that is surfing my site?
Showing the correct timezone?
Moderator: General Moderators
Re: Showing the correct timezone?
A. Use Javascript to convert the server's time to the client's time in the browser.
B. Use Javascript to find the offset between the client's timezone and UTC. Pass the offset back to the server using AJAX or in a link or form variable. Save the timezone offset in a session variable. Calculate the client's time on the server.
To display the client's timezone offset:
To set your server to use UTC in php.ini:
or at runtime:
Edit: This post was recovered from search engine cache.
B. Use Javascript to find the offset between the client's timezone and UTC. Pass the offset back to the server using AJAX or in a link or form variable. Save the timezone offset in a session variable. Calculate the client's time on the server.
To display the client's timezone offset:
Code: Select all
<script type="text/javascript">
var date = new Date();
var offset = date.getTimezoneOffset();
document.write('UTC Offset: ' + parseFloat(offset) + ' Minutes');
</script>Code: Select all
date.timezone = UTCCode: Select all
date_default_timezone_set('UTC');
Last edited by McInfo on Tue Jun 15, 2010 10:10 pm, edited 1 time in total.
Re: Showing the correct timezone?
Please refer to this thread: viewtopic.php?p=507769#p507769
You can get current offset in this way, but you can't use it for dates in the past or future, because on that dates offset might be different. Again, please refer to the thread I linked above — it's not as simple as you seem to think.McInfo wrote: Use Javascript to find the offset between the client's timezone and UTC