Very often we are faced with the problem of adjusting ourself to local time where application need to run at a different time than the servers local time. This happens when client is located in a different time zone, and the software is time dependent.
this works by storing the time zone values/differences in the user/client profile, in format of +0n00 or -0n00 where n is the number of hours. when this code is run through a parser, it can be extremely usefull for solving time zone problems, by letting you switch amaong time zones flexibly
Now we have a way to do that by setting TZ variable using putenv() method. But due to the non-availability of standard time zone codes, developers are often faced with the ambiguity of how to implement a non standard time zone(those which are not too popular)
I figured a way out myself for this. It uses the information that a particular time zone is n hours ahead or n hours behind standard GMT time zone.
here is what i did.
<?php
$day=15;
$month=12;
$year=2003;
//convert it to unix timestamp
$deadline=mktime('','','',$month,$day,$year);
//caluculate our time from GMT time
$hour=gmdate('H');
$min=gmdate('i');
$sec=gmdate('s');
$month=gmdate('n');
$day=gmdate('d');
$year=gmdate('Y');
$stamp=mktime ($hour,$min,$sec,$month,$day,$year);
// technique is to convert the GMT date & time to unix stamp, then convert time zone
//specific information like add 5 hours or subtract 5 hours to seconds,(consider day
//light saving here), and add/subtract it to the unix time stamp and then convert
//it back to date using date function if needed or perform operations needed on the
// time stamp
//subtract 6/n hours from GMT time (Central standard time/CST)
//vary this part to whatever time zone you are at
$do=6*60*60;
$lstamp=$stamp-$do;
echo("Today(local date/Central):".date('h:i:s d/n/Y',$lstamp)."<br>");
$left=$deadline-$lstamp;
$days_left=floor($left/(24 * 60 * 60));
$hours_left=floor($left/(60 * 60 ));
echo "<br>Days Left: $days_left<br>";
echo "<br>Hours Left(approx): $hours_left<br>";
?>
Change the $do variable to whatever seconds you are different from GMT and add or subtract accordingly to generate $lstamp.
This would solve your time zone problems.
Happy Coding,
Suneel Kanuri🙂
http://coolguide.net/res.php