How to convert one time zone to anothor time zone
In this post we will give you information about How to convert one time zone to anothor time zone. Hear we will give you detail about How to convert one time zone to anothor time zoneAnd how to use it also give you demo for it if it is necessary.
Some application required one time zone to convert another time zone.
PHP provide some readymade timezone conversion classes but it a very complecated. so we have try to define this function simple way.
You can createe a simple class and write one function into the class. then you able to use this function everywere.
class convertTimezone
{
function convert_timezone() // Constructor of the class
{
}
function converToTime($conv_fr_zon=0,$conv_fr_time="",$conv_to_zon=0)
{
//echo $conv_fr_zon;
$cd = strtotime($conv_fr_time);
$gmdate = date('Y-m-d H:i:s', mktime(date('H',$cd)-$conv_fr_zon,date('i',$cd),date('s',$cd),date('m',$cd),date('d',$cd),date('Y',$cd)));
//echo $gmdate";
$gm_timestamp = strtotime($gmdate);
$finaldate = date('Y-m-d H:i:s', mktime(date('H',$gm_timestamp )+$conv_to_zon,date('i',$gm_timestamp ),date('s',$gm_timestamp ),date('m',$gm_timestamp ),date('d',$gm_timestamp ),date('Y',$gm_timestamp )));
return $finaldate;
}
}
Example For Use
$c = new convertTimezone();
$resultTime = $c->converToTime(5.30, “2011-05-09 11:00:00”, -13);
$resultTime = $c->converToTime(-4, “2011-05-09 11:00:00”, 10);
The first one converts 5th May, 2011, 11 am from the timezone GMT+0530hrs to GMT-1300hrs
The second one coverts 5th May,2011 11 am from the timezone GMT-0400hrs to GMT1000 hrs
Hope this code and post will helped you for implement How to convert one time zone to anothor time zone. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs