Page 1 of 1
Showing the correct timezone?
Posted: Thu Jun 04, 2009 1:59 pm
by psxmetal
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?
Re: Showing the correct timezone?
Posted: Thu Jun 04, 2009 3:41 pm
by McInfo
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:
Code: Select all
<script type="text/javascript">
var date = new Date();
var offset = date.getTimezoneOffset();
document.write('UTC Offset: ' + parseFloat(offset) + ' Minutes');
</script>
To set your server to use UTC in php.ini:
or at runtime:
Edit: This post was recovered from search engine cache.
Re: Showing the correct timezone?
Posted: Thu Jun 04, 2009 6:41 pm
by Weirdan
Please refer to this thread:
viewtopic.php?p=507769#p507769
McInfo wrote:
Use Javascript to find the offset between the client's timezone and UTC
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.