简体   繁体   中英

How to get client timezone in PHP

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM