Saturday, April 12, 2014

How to get Default Timezone in PHP

Here i will talk about timezone which you can't get in PHP there is no built in function to get that.... But here i am with a new technique to get timezone in PHP using Javascript. Let's do it.

First of all Download a small js file from top of this website. Put this file in js folder and replace the name here bold in code


function timeStamp(){
    echo '<script type="text/javascript" src="'js/jstie.min.js" /></script>';
    echo '<script type="text/javascript">';
    echo "var timezone = jstz.determine();";

    $timezoni = "document.write(timezone.name());";
    echo "</script>"; 

    timeStamp();
    date_default_timezone_set($timezoni);

That's all now your timezone will be save in variable $timezoni nothing difficult just call the function timeStamp();  you will get a variable timezoni and put that in date_default_timezone_set() this is the PHP function to set a specific timezone but we do it dynamically.

Hope you will like this tutorial and you going to comment and share this with your friend.

0 comments:

Post a Comment

Please Don't write wrong comments.
.
Please write good comments or mistakes ...