Convert current time set here to another time zone

@param *string     $zone   valid UTC, GMT, PHP Location or TZ Abbreviation
@param string|null $format format

@return string|int
19648
public function convertTo($zone, $format = null)
    {
        Argument::i()
            //argument 1 must be a string
            ->test(1, 'string')
            //argument 1 must be a timezone identifier
            ->test(1, 'location', 'utc', 'abbr')
            //argument 2 must be a string or null
            ->test(2, 'string', 'null');

        $time = $this->time + $this->calculateOffset($zone);

        if (!is_null($format)) {
            return date($format, $time);
        }

        return $time;
    }
180933
public function format($format = 'local', $timezone = null)
	{
		// custom format pattern lookup
		if (array_key_exists($format, static::$patterns))
		{
			$format = static::$patterns[$format];
		}

		// save the objects timezone
		$orginalTimezone = $this->datetime->getTimezone();

		// default GMT offset
		$offset = 0;

		// want to output in the application default timezone?
		if ($timezone === true)
		{
			$timezone = static::defaultTimezone();
		}

		// output timezone specified?
		elseif ($timezone)
		{
			if ( ! $timezone instanceOf DateTimeZone)
			{
				$this->datetime->setTimezone($timezone = new DateTimeZone($timezone));
			}
		}

		// output in the current timezone
		else
		{
			$timezone = $orginalTimezone;
		}


		// strftime will always do UTC to local time, and
		// strptime() does timezones but no daylight savings,
		// so we might need a correction here

		// offsets are to UTC, so first, UTC -> given timezone, second, UTC -> current object timezone
		$testdate1 = new DateTime('@'.$this->datetime->getTimestamp(), $orginalTimezone);
		$testdate2 = new DateTime('@'.$this->datetime->getTimestamp(), $timezone);

		// offset is the delta between both
		$offset = $timezone->getOffset($testdate1) - $orginalTimezone->getOffset($testdate2);

		// Create output
		if (strpos($format, '%') === false)
		{
			$result = $this->datetime->format($format);
		}
		else
		{
			$result = strftime($format, $this->datetime->getTimestamp() + $offset);
			if (static::$encoding)
			{
				$result = static::$encoding == 'UTF8' ? utf8_encode($result) : iconv('ISO8859-1', static::$encoding, $result);
			}
		}

		// restore the timezone if needed
		if ($timezone !== null)
		{
			$this->datetime->setTimezone($orginalTimezone);
		}

		return $result;
	}
1322307
public function setFormat($format)
    {
        if (!is_null($format)) {
            $this->format = $format;
            $this->useFormat(false);
        }

        return $this;
    }
899878
public function currentInterval($format = null)
    {

        // Relative time formatting
        $abbreviated = [
            'pluraling' => false,
            'spacing' => false,
            'labels' => ['now', 's', 'm', 'h', 'd', 'm', 'y'],
        ];

        // Figure stuff out
        if ($this->isRunning()) {
            $interval = $this->WORKER_SLEEP_SECS;
        } else {
            $check = Cache::get($this->HEARTBEAT_CRON_KEY);
            if (empty($check)) {
                $interval = 'uncertain';
            } else {
                $interval = $check->interval;
            }
        }

        // Format it
        if (!is_numeric($interval)) {
            return $interval;
        }
        switch ($format) {
            case 'raw':
                return $interval;

            case 'abbreviated':
                return Library\Utils\Text::timeElapsed(time() - $interval, $abbreviated);

            default:
                return Library\Utils\Text::timeElapsed(time() - $interval);
        }
    }
234796
protected function convertDateFormatToMoment($format)
    {
        $replacements = [
            'd' => 'DD',
            'D' => 'ddd',
            'j' => 'D',
            'l' => 'dddd',
            'N' => 'E',
            'S' => 'o',
            'w' => 'e',
            'z' => 'DDD',
            'W' => 'W',
            'F' => 'MMMM',
            'm' => 'MM',
            'M' => 'MMM',
            'n' => 'M',
            't' => '', // no equivalent
            'L' => '', // no equivalent
            'o' => 'YYYY',
            'Y' => 'YYYY',
            'y' => 'YY',
            'a' => 'a',
            'A' => 'A',
            'B' => '', // no equivalent
            'g' => 'h',
            'G' => 'H',
            'h' => 'hh',
            'H' => 'HH',
            'i' => 'mm',
            's' => 'ss',
            'u' => 'SSS',
            'e' => 'zz', // deprecated since version 1.6.0 of moment.js
            'I' => '', // no equivalent
            'O' => '', // no equivalent
            'P' => '', // no equivalent
            'T' => '', // no equivalent
            'Z' => '', // no equivalent
            'c' => '', // no equivalent
            'r' => '', // no equivalent
            'U' => 'X',
        ];

        foreach ($replacements as $from => $to) {
            $replacements['\\' . $from] = '[' . $from . ']';
        }

        return strtr($format, $replacements);
    }
1054447
public function format(string $format): string
    {
        return CommonTime::inSeconds($this->seconds)->format($format);
    }
1202500
public function formatTimepoint($time, $format)
    {
        if ($time instanceof TimePoint) {
            return $time->format($format, $this->displayTimezone);
        }

        if ($time instanceof DateTime) {
            $formatted = clone $time;
            $formatted->setTimezone(new DateTimeZone($this->displayTimezone));
            return $formatted->format($format);
        }

        return '';
    }
638358
public static function createFromFormat( $format, $time, $timezone = null ) {

		/** @var \DateTimeInterface $created */
		$created = empty( $timezone ) ?
			parent::createFromFormat( $format, $time ) :
			parent::createFromFormat( $format, $time, $timezone );

		if ( false === $created ) {
			return false;
		}

		$wp_date_time = new static( '@' . $created->getTimestamp() );

		return $wp_date_time->setTimezone( $created->getTimezone() );
	}
156032
static public String getFormattedDateTime(long dt, TimeZone tz, String format)
    {
        SimpleDateFormat df = new SimpleDateFormat(format);
        if(tz != null)
            df.setTimeZone(tz);
        return df.format(new Date(dt));
    }
337916
public function getTimezoneHourOffset($origin_tz = 'UTC', $format = 'h') {
        $remote_tz = 'UTC';
        if ($origin_tz === 'UTC') {
            return 0 . 'h';
        }
        $origin_dtz = new \DateTimeZone($origin_tz);
        $remote_dtz = new \DateTimeZone($remote_tz);
        $origin_dt = new \DateTime("now", $origin_dtz);
        $remote_dt = new \DateTime("now", $remote_dtz);

        $offset =  $remote_dtz->getOffset($remote_dt) - $origin_dtz->getOffset($origin_dt);
        return $offset / 3600 . $format;
    }
729921
public function convertTimestamp($date, $format)
    {
        if (! is_numeric($date)) {
            $date = strtotime($date);
        }
        
        return $this->getDt()
            ->createFromTimestamp($date, $this->getTz())
            ->format($format);
    }
491836
public function getCreatedTime($format = "")
    {
        $time = $this->created_time;
        if (!empty($format)) {
            $timestamp = strtotime($time);
            $time      = date($format, $timestamp);
        }

        return $time;
    }
416646
public static function _utcDate ($format = 'Y-m-d H:i:s', $time = FALSE)
	{
		return $time? gmdate ($format, $time) : gmdate ($format);
	}
180968
public function formatEnd(string $format, TimeZone $timeZone = null): string
    {
        return $this->end->format($format, $timeZone);
    }
980785
public function getTimestamp($format = self::TIMESTAMP_FORMAT_RFC1123) {
		$this->ensureInput();
		if(!isset($this->input['timestamp'])) return null;
		switch($format) {
			case static::TIMESTAMP_FORMAT_UNIX:
				return strtotime($this->input['timestamp']);
			case static::TIMESTAMP_FORMAT_RFC1123:
			default:
				return $this->input['timestamp'];
		}
	}
274224
final protected function _getTimeZone($timezone = null)
	{
		if ($timezone = strtoupper($timezone) and defined("\\DateTimeZone::{$timezone}")) {
			$timezone = new \DateTimeZone($timezone);
		} elseif (! ($timezone instanceof \DateTimeZone)) {
			@date_default_timezone_set(date_default_timezone_get());
			$timezone = new \DateTimeZone(date_default_timezone_get());
		}
		return $timezone;
	}
717796
public function format($format = 'date', $timestamp = null)
    {
        $timestamp = is_numeric($timestamp) ? '@'.intval($timestamp) : $timestamp;
        $timestamp = is_a($timestamp, 'DateTime') ? $timestamp : new DateTime($timestamp);

        $key = $this->getTranslationKey("date.formats.{$format}");
        $format = $this->translator->has($key) ? $this->translator->get($key) : null;

        if (is_null($format)) {
            throw new \InvalidArgumentException('Date format is invalid or does not exists in current language');
        }

        return strftime($format, $timestamp->format('U'));
    }