Convert time and date from one time zone to another in PHP

Sometimes we have required current time according to the different country base. But the server provides the only US and another country location time zone according to hosting.

We provide you small function for your related time converter, this function provides you current time according to the different country base. If you get value database and pass date in this function, it will automatically convert country base.

   function get_current_time(){
        $CI = get_instance();
        $ip_address = getenv('HTTP_CLIENT_IP') ?:
      getenv('HTTP_X_FORWARDED_FOR') ?: getenv('HTTP_X_FORWARDED') ?:
      getenv('HTTP_FORWARDED_FOR') ?: getenv('HTTP_FORWARDED') ?:
      // Get JSON object
      $jsondata = file_get_contents("" .
      // Decode
      $data = json_decode($jsondata, true);
      // Request OK?
      if($data['meta']['code'] == '200'){          
        return $currenttime;

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *