0

I have a script that outputs some data along whith a tag like "added 1 hour ago" . Now, if the timezone on the server is the same as the user;s timezone it will do it fine.

I know that user's timezone can be obtained by JavaScript, but how do I sent offset to the PHP script before the data is displayed? a body onload function? append a parameter to the main page that will show the content?

timezone on server is set to UTC

thx

user1965451
  • 327
  • 2
  • 4
  • 12
  • 3
    Why is this important? If the user is in another timezone, the post is still 1 hour old. Use the server time for both. – Oliver Mar 02 '13 at 05:48
  • 1
    Check this link http://stackoverflow.com/questions/8090549/how-to-get-user-timezone-using-jquery – Nirmal Ram Mar 02 '13 at 05:52

1 Answers1

2

You can get the user's timezone in javascript and then make a ajax request to some file and in that file you can do like this

$tz = $_POST['tz'];
date_default_timezone_set($tz);
echo  date('Y-m-d H:i:s');
Nirmal Ram
  • 1,722
  • 4
  • 25
  • 45