Location: PHPKode > scripts > Time Zone Converter > time-zone-converter/convert_timezone.php
<?php
class convert_timezone
{
	/** This class is for Converting Time form One Time Zone to Another Time Zone
		It shows the Converted Time.
	
->	conver_to_time() accepts three perameters
	
	$conv_to_zon = Time Zone in which we want to convert The specified time
	$conv_fr_zon = Time Zone in Which we speicified time.
	conv_fr_time = Time wich we want to convert
	
	***********************************************************************
	Note: Time Zone values are  Hours difference from GMT
	
	eg. If You want to convert GMT+5 from GMT-3 then
		$conv_fr_zon = 5
		$conv_to_zon=-3
	***********************************************************************
	
->	makeproper() Calculate day,month and year as per value.
	
	***********************************************************************
	Note: This Class is not calculate DayLight Saving
	***********************************************************************

***********************************************************************
Author : Ritesh Patel
Mob: +91 9879790368
email : hide@address.com
***********************************************************************

	
	*/	
	

	function convert_timezone() // Constructor of the class
	{
	}//function convert_timezone()
	
	function conver_to_time($conv_fr_zon=0,$conv_fr_time="",$conv_to_zon=0)
	{
		$date_val_arr=explode(" ",$conv_fr_time);
		$send_date=$date_val_arr[0];
		
		$conv_hour_val=explode(":",$date_val_arr[1]);
				
		$time_diff=$conv_fr_zon-$conv_to_zon;
		
		$time_val=date("H:i:s",(time()+($time_diff*60*60))); 
		$time_arr=explode(":",$time_val);
		$time_diff_arr=explode(".",$time_diff);
		
		$hour=$conv_hour_val[0];
		$hour=$hour-$time_arr[0];
		
		$send_hour=date("H");
		$send_hour=$send_hour+($hour);
		
		$send_minit=$conv_hour_val[1];
		$send_minit=$send_minit-$time_arr[1];
		
		$minit=date("i");
		$minit=$minit+($send_minit);
		
		if($time_diff<0)
			$send_hour=$send_hour-1;
		
							
		if($minit==-1)
		{
			if($time_diff>=0)
			$send_hour=$send_hour-1;
			$minit=59;
		}
		if($minit>=60)
		{
			$send_hour=$send_hour+1;
			$minit=$minit-60;
			$tmp_send_minit=$minit;
		}
		
		if($send_hour>24)
		{
			$send_date_arr=explode("-",$send_date);
			$send_date_arr[2]=$send_date_arr[2]+1;
			$send_date_arr=$this->makeproper($send_date_arr);
			
			if($send_date_arr[2]<10)
			$send_date_arr[2]="0".$send_date_arr[2];
					
			$send_hour=$send_hour-24;
			$send_date=implode("-",$send_date_arr);
			
		}
		elseif($send_hour<0)
		{
			$send_date_arr=explode("-",$send_date);
			$send_date_arr[2]=$send_date_arr[2]-1;
			$send_date_arr=$this->makeproper($send_date_arr);
			
			if($send_date_arr[2]<10)
			$send_date_arr[2]="0".$send_date_arr[2];
			
			$send_date=implode("-",$send_date_arr);
			$send_hour=$send_hour+24;
		}
		$minit=abs($minit);
		if(abs($send_hour)<10)
			$send_hour="0".$send_hour;
		if($minit<10)				
			$minit="0".$minit;
		$send_str=$send_date." ".$send_hour.":".$minit; 
		return $send_str;
	}//function conver_to_time($conv_to_zon,$conv_fr_zon,$conv_fr_time="")
	
	function makeproper($arr)
	{
		$tempmonth=$arr[1]-1;
		if($tempmonth==2)
		{
			if($arr[0]%4==0)
			{
				if($arr[2]>29)
				{
					$arr[1]=$arr[1]+1;
					$arr[2]=1;
				}
				elseif($arr[2]<=0)
				{
					$arr[1]=$arr[1]-1;
					$arr[2]=29;
				}
			}
			else
			{
				if($arr[2]>28)
				{
					$arr[1]=$arr[1]+1;
					$arr[2]=1;
				}
				elseif($arr[2]<=0)
				{
					$arr[1]=$arr[1]-1;
					$arr[2]=28;
				}
			}
		}
		elseif($tempmonth==1 || $tempmonth==3 || $tempmonth==5 || $tempmonth==7 || $tempmonth==8 || $tempmonth==10 || $tempmonth==12)
		{
			if($arr[2]>31)
			{
				$arr[1]=$arr[1]+1;
				$arr[2]=1;
			}
			elseif($arr[2]<=0)
			{
				$arr[1]=$arr[1]-1;
				$arr[2]=31;
			}
		}
		elseif($tempmonth==4 || $tempmonth==6 || $tempmonth==9 || $tempmonth==11)
		{
			if($arr[2]>30)
			{
				$arr[1]=$arr[1]+1;
				$arr[2]=1;
			}
			elseif($arr[2]<=0)
			{
				$arr[1]=$arr[1]-1;
				$arr[2]=30;
			}
		}
		return $arr;
	}

}//class convert_timezone


?>
Return current item: Time Zone Converter