PHP : convert date to another time zone

function converToTz($time=””,$toTz=”,$fromTz=”)
{
// timezone by php friendly values
$date = new DateTime($time, new DateTimeZone($fromTz));
$date->setTimezone(new DateTimeZone($toTz));
$time= $date->format(‘Y-m-d H:i:s’);
return $time;
}
echo date_default_timezone_get();
echo converToTz(‘2019-08-07 13:00:00’, ‘UTC’, ‘Asia/Calcutta’);

PHP : Get all Timezones

<?php

$tzlist = DateTimeZone::listIdentifiers(DateTimeZone::ALL);

foreach($tzlist as $val){

$date = new DateTime(date(‘Y-m-d H:i:s’), new DateTimeZone($val));
$tz[] = $date->format(‘P’);
echo $val .” == “. $date->format(‘P’);

}

//print_r(array_unique($tz));

$date = new DateTime(date(‘Y/m/j H:i:s’), new DateTimeZone(‘Asia/Kolkata’));
echo $date->format(‘Y/m/j H:i:sP’) . “<br/>”;

$timezone¬† = “+05:30”;
echo gmdate(“Y/m/j H:i:s”, time() + 3600*($timezone+date(“I”)));

PHP : DB Connection

<?php

/**
* Handling database connection through PDO
*/
class DbConnect {

/**
*Class is use for to create the connection, also here we have assign tables name
*/

public $conn = null;

/**
*Tables Name
*/

public $tablePrifix ;

function __construct() {
$this->conn =  $this->connect();
$this->tablePrifix = TABLE_PREFIX;
}

/**
* Create a connection with database using PDO
* @return type
*/
function connect() {
if ($this->conn == null) {
try {
$this->conn = new PDO(‘mysql:dbname=’ . DB_NAME . ‘;port=’ . DB_PORT . ‘;host=’ . DB_HOST, DB_USERNAME, DB_PASSWORD);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$this->conn->exec(“set names utf8”);
} catch (PDOException $e) {
echo $e->getMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
}
// returing connection resource
return $this->conn;
}

}

$db = new DbConnect();
$select = “SELECT count(0) FROM {$db->tablePrifix}{$db->deviceToken}”;
$where = ” WHERE device_id = :device_id AND type = :type”;
$query = $db->conn->prepare($select . $where);
$query->bindParam(‘:device_id’, $this->deviceId, PDO::PARAM_STR);
$query->bindParam(‘:type’, $this->deviceType, PDO::PARAM_STR);
$query->execute();
return $query->fetchColumn();

ZF2 : Finish Event

public function onBootstrap(Event $e)
{
    $app = $e->getTarget();
    $app->getEventManager()->attach('finish', array($this, 'doSomething'), 100);
}


public function doSomething ($e)
{
    $response = $e->getResponse();
    $content = $response->getBody();
    // do stuff here
    $response->setContent($content);

}