DateTime and DateTimeZone classes, so in order to simplify that, I came up with the following:
$formatUTCDateTime = function($dts, $format = null, $tz = null) {
if($format === null)
$format = 'Y-m-d H:i:s T';
if($tz === null)
$tz = date_default_timezone_get();
$dtz = new DateTimeZone('UTC');
$dt = new DateTime($dts, $dtz);
$dt->setTimezone(new DateTimeZone($tz));
return $dt->format($format);
};
This method supports a default datetime format and will default the timezone to the currently configured timezone. This will be set dynamically according to the local time of the user (as set by date_default_timezone_set()) and will make the conversion process transparent.
const MY_CONSTANT = 1;
// get constant name by value
$class = new ReflectionClass('MyClassName');
$constants = array_flip($class->getConstants());
echo $constants[1];
// output is "MY_CONSTANT"
If you’re in an instance method and want to retrieve the constants of the current class, use get_class($this) here for the ReflectionClass constructor argument.