Display local country time, instent of displaying server time using SafGetLocalTime

<?
//Display local country time, instent of displaying server time,
//If you country is Sri Lanka and web server in in USA, you can use the following script to solve your problem
//$datetime variable shuld contain the date time like date('Y-m-d H:i:s')
//$diferent variable is the diferent between server and your local country like +5.5 -6
//$mylenth from the final out put you can tell to the function how many character from $myafter sould display
//better to keep $myafter=0 and $mylenth=0 as it is

function SafGetLocalTime($datetime,$myafter=0,$mylenth=0,$diferent){ //get local time pass datetime and diferent
list($year,$month,$day,$hour,$minute,$second) = explode("-",str_replace(array(" ",":"),"-",$datetime));
$hour = ($hour+$diferent);
$datetime = mktime($hour,$minute,$second,$month,$day,$year);

if (
$mylenth==0) {
$datetime = date('Y-m-d H:i:s',$datetime);
}else{
$datetime = date('Y-m-d H:i:s',$datetime);
$datetime = substr($datetime,$myafter,$mylenth);
}
return
$datetime;
}
?>