Get Default Timezone in PHP using JavaScript

Sometime getting users own country time becomes problem. Get Correct Timezone of current place using PHP. Due to some limitation you can't get current timezone & hence result in currency count problem. A simple library to get current timezone.

Share

Most of the time correct timezone in PHP become an headache. When you work with twitter like time stamp, (i.e. 1 minute ago), then this JavaScript library will get you the perfect timezone according to their country.Here is the simple tutorial on How to Get Default Timezone in PHP.

JsTimezoneDetect, JavaScript library which  determines perfect timezone, helps you to solve different kinds of problem. e.g. display currency according to your country, time detection or GMT detection, Coupon time left according to region etc. So there are no limitations in the scrip as writer says.

The script do not do Geo location but very useful and will not let your user select their country or others. Relaying on this script is usable and will help you to add key feature in your website and provide usability regarding  date-time across timezone.

Get Default Timezone in PHP

First Include a small minified js file in your page. Get it from the top of this website. Include it in your document or  on your page,

function timeStamp(){
?>
<script type="text/javascript">
var timezone = jstz.determine();
<?php
$timezoni = "document.write(timezone.name());";
?>
</script>
<?php
timeStamp();
date_default_timezone_set($timezoni);
}
?>

Your timezone now in the variable called $timezoni, so you can use it alone to paste a timezone. Also another function date_default_timezone_set() is the PHP built in function which set the timezone for the user. so we set the timezone by giving it a variable, saying that my timezone will be this and do all according to my desired timezone. Now you can use timestamp(); function which will return you the timezone or you can extend for the user time not the server time.

Hope you like the tutorials if anything wrong happens then do comment we will try to help you regarding this.

Leave a Reply

Your email address will not be published. Required fields are marked *