src/Common/Service/DateTime.php
public static function convert($mTimestamp, $sToTz, $sFromTz = 'UTC')
    {
        //  Has a specific timestamp been given?
        if (is_null($mTimestamp)) {

            $oDateTime = Factory::factory('DateTime');

        } elseif (is_numeric($mTimestamp)) {

            $oDateTime = Factory::factory('DateTime');
            $oDateTime->setTimestamp($mTimestamp);

        } elseif ($mTimestamp instanceof \DateTime) {

            $oDateTime = $mTimestamp;

        } elseif (!empty($mTimestamp) && $mTimestamp !== '0000-00-00' && $mTimestamp !== '0000-00-00 00:00:00') {

            $oDateTime = new \DateTime($mTimestamp);

        } else {
            return null;
        }

        // --------------------------------------------------------------------------

        //  Perform the conversion
        $oFromTz = new \DateTimeZone($sFromTz);
        $oToTz   = new \DateTimeZone($sToTz);
        $oOut    = new \DateTime($oDateTime->format('Y-m-d H:i:s'), $oFromTz);

        $oOut->setTimeZone($oToTz);

        return $oOut;
    }
public static function convert($mTimestamp, $sToTz, $sFromTz = 'UTC')
    {
        //  Has a specific timestamp been given?
        if (is_null($mTimestamp)) {

            $oDateTime = Factory::factory('DateTime');

        } elseif (is_numeric($mTimestamp)) {

            $oDateTime = Factory::factory('DateTime');
            $oDateTime->setTimestamp($mTimestamp);

        } elseif ($mTimestamp instanceof \DateTime) {

            $oDateTime = $mTimestamp;

        } elseif (!empty($mTimestamp) && $mTimestamp !== '0000-00-00' && $mTimestamp !== '0000-00-00 00:00:00') {

            $oDateTime = new \DateTime($mTimestamp);

        } else {
            return null;
        }

        // --------------------------------------------------------------------------

        //  Perform the conversion
        $oFromTz = new \DateTimeZone($sFromTz);
        $oToTz   = new \DateTimeZone($sToTz);
        $oOut    = new \DateTime($oDateTime->format('Y-m-d H:i:s'), $oFromTz);

        $oOut->setTimeZone($oToTz);

        return $oOut;
    }
public static function convert ( $ mTimestamp , $ sToTz , $ sFromTz = 'UTC' ) { //  Has a specific timestamp been given? if ( is_null ( $ mTimestamp ) ) { $ oDateTime = Factory :: factory ( 'DateTime' ) ; } elseif ( is_numeric ( $ mTimestamp ) ) { $ oDateTime = Factory :: factory ( 'DateTime' ) ; $ oDateTime -> setTimestamp ( $ mTimestamp ) ; } elseif ( $ mTimestamp instanceof \ DateTime ) { $ oDateTime = $ mTimestamp ; } elseif ( ! empty ( $ mTimestamp ) && $ mTimestamp !== '0000-00-00' && $ mTimestamp !== '0000-00-00 00:00:00' ) { $ oDateTime = new \ DateTime ( $ mTimestamp ) ; } else { return null ; } // -------------------------------------------------------------------------- //  Perform the conversion $ oFromTz = new \ DateTimeZone ( $ sFromTz ) ; $ oToTz = new \ DateTimeZone ( $ sToTz ) ; $ oOut = new \ DateTime ( $ oDateTime -> format ( 'Y-m-d H:i:s' ) , $ oFromTz ) ; $ oOut -> setTimeZone ( $ oToTz ) ; return $ oOut ; }
Arbitrarily convert a timestamp between timezones

@param mixed  $mTimestamp The timestamp to convert. If null current time is used, if numeric treated as timestamp, else passed to strtotime()
@param string $sToTz      The timezone to convert to
@param string $sFromTz    The timezone to convert from

@return \DateTime|null
Arbitrarily convert a timestamp between timezones