-3

I am searching for PHP code which can get automatically timezone of client side. I had searched, and I found javascript who get timezone. How can I convert and use JavaScript in PHP to get timezone automatically?

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 
<script type="text/javascript">
function get_time_zone_offset( ) {
var current_date = new Date( );
var gmt_offset = current_date.getTimezoneOffset( ) / 60;
return gmt_offset;
}
$('#offset').html( get_time_zone_offset( ) );
</script>

Please help me to convert this code into PHP and call this function into echo.

I will be very thankful to you guys.

fazi
  • 11
  • 4
  • 1
    It's not at all clear to me what you mean. You just need to make sure that your PHP serves the appropriate Javascript as part of its HTML response... you *are* serving HTML from your PHP, right? – Jon Skeet Dec 25 '14 at 21:14
  • http://blog.codez.in/php5-time-zone-solution/web-development/2010/07/09 might help you – Tushar Gupta Dec 25 '14 at 21:16
  • 1
    http://stackoverflow.com/questions/16525617/how-to-detect-users-timezone http://stackoverflow.com/questions/1905397/how-to-get-clients-timezone http://stackoverflow.com/questions/13/determining-a-web-users-time-zone http://stackoverflow.com/questions/5203382/how-to-automatically-detect-users-timezone – chrki Dec 25 '14 at 21:17
  • i want to calculate timezone with the help of javascript and use this information in php and then show this with the help of echo. – fazi Dec 25 '14 at 21:17
  • @fazi if your end goal is to show it then why bother with php? – David Sherret Dec 25 '14 at 21:18
  • you r right but you know basically i am creating a php script which calculate prayer time and prayer time depend on sunrise and sunset so in euorope the time zone is +1 and -1h so now i want a code in php that calculate automatically timezone and set the dates automatically – fazi Dec 25 '14 at 21:22
  • Timezone != timezone offset – symcbean Dec 25 '14 at 21:37
  • guys i will put my all the code here so you can see what i had done and then i will explain that to you. – fazi Dec 25 '14 at 21:41

1 Answers1

0

You may send timezone_offset to the server via ajax. You may store it somewhere on the server then. Or you may set a cookie with this value so it may be used on next page load.

But if you need to calculate and immedeately show it to the user - you better use javascript and maybe cookie for next page load.

Sergiy T.
  • 1,433
  • 1
  • 23
  • 25