<?php

function dateShow() { //Show the current date on the webpage.
$dateshow = date("l jS \of F Y h:i:s A") . "<br>";
return $dateshow;
}
echo "GMT: " . dateShow() . "\r\n";

$dt = new DateTime();
$dt->setTimezone(new DateTimeZone('America/New_York'));
$dt->setTimestamp(-46777879);
echo "Date X is: " . $dt->format('F j, Y @ G:i') . "\r\n";

//https://stackoverflow.com/questions/20288789/php-date-with-timezone
$tz = 'America/New_York';
$timestamp = time();
$dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
$dt->setTimestamp($timestamp); //adjust the object to correct timestamp
echo $tz ." date/time is: " . $dt->format('Y-m-d H:i:s') . "\r\n";

//Pass the timezone and time format to the tzone function:
//Example: tzone("America/Phoenix","Y-m-d h:i:s");
function tzone($tz,$fmt) {
//$tz = 'Europe/London';
$timestamp = time();
$dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
$dt->setTimestamp($timestamp); //adjust the object to correct timestamp
//echo $tz ." date/time is: " . $dt->format('Y-m-d H:i:s');
$zz = $tz ." date/time is: " . $dt->format($fmt);
return $zz;
}
echo "TZone: " . tzone("America/Phoenix","l jS \of F Y h:i:s A") . "\r\n";
echo "TZone: " . tzone("America/Phoenix","Y-M-d H:i:s A") . "\r\n";
echo "TZone: " . tzone("America/Phoenix","Y-m-d h:i:s") . "\r\n";
echo "TZone: " . tzone("America/Phoenix","YmdHism") . "\r\n";

//$t = microtime(true);
$t = "1968-07-08 10:07:00.000";
$now = DateTime::createFromFormat('U.u', sprintf('%f', $t));
echo "ZZZZ: " . $now = $now->format("H:i:s.v") . "\r\n";

$test = 'Fri, 15 Jan 2016 15:14:10 +0800';
echo "Test variable: " . (new DateTime($test))->format("Y-m-d H:i:s") . "\r\n";
?>