Retrieves formated date time using timezone.

@param UTCDateTime $date
@param string      $format

@return string
336099
public static function format(
        UTCDateTime $date,
        string $format = 'd/m/Y H:i:s'
    ): string {
        return self::get($date)->format($format);
    }
270487
public static function isDateTime($date, string $format = null): bool
    {
        if ($date instanceof \DateTime) {
            return true;
        }

        if (false === is_string($date)) {
            return false;
        }

        if ($format) {
            return \DateTime::createFromFormat($format, $date) instanceof \DateTime;
        }

        return (bool)strtotime($date);
    }
905167
public function getDateTimeFormat(string $format='Y-m-d H:i:s')
    {
        $this->setDateTimeZone()->setDateTime();

        return $this->dateTime->format($format);
    }
1129527
public function date($field, $format)
    {
        $fieldValue = $this->get($field);

        try {

            $date = new \DateTime($fieldValue);

            return $fieldValue === $date->format($format);
        } catch (\Exception $exception) {
            return $this->error($field, __FUNCTION__);
        }
    }
215105
protected function getDateTimeWithOptionalFormat( $format, $value )
	{
		$date = DateTime::createFromFormat( $format, $value );

		if ( $date )
		{
			return $date;
		}

		try
		{
			return new DateTime( $value );
		}
		catch ( Exception $e )
		{
			//
		}
	}
1087450
public function getTime(string $format = null)
    {
        $time = $this->time + $this->offset;

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

        return $time;
    }
824726
public static function dateSQL($date, $format = 'd-m-Y')
    {
        if (empty($date)) {
            return null;
        }

        $obj = DateTime::createFromFormat('Y-m-d H:i:s', $date);
        if (empty($obj)) {
            return null;
        }

        return $obj->format($format);
    }
790629
public function getDisplayDateTime($input, $format = null, $timezone = null)
    {
        return \enpii\enpiiCms\helpers\DateTimeHelper::fromDbFormat($input,
            ($format === null ? $this->datetimeFormat : $format),
            ($timezone === null ? $this->timezone : $timezone));
    }
257176
public function format(string $format) : string
    {
        $format = $this->escapeUnapplicableFormatChars($format);

        return $this->dateTime->format($format);
    }
614829
public static function toServerTime($date, $format = null, $from = null)
    {
        self::backupTimezone();

        $from = $from ?: Ioc::getConfig()->get('system.timezone');

        return static::convert($date, $from, self::$stz->getName(), $format);
    }
1222286
public function prettyDate($date, $format = null)
    {
        if (is_string($date)) {
            $date = new \DateTime($date);
        }

        if (null !== $format) {
            return $this->dateFormatter->prettyDate($date, $format);
        }

        return $this->dateFormatter->prettyDate($date);
    }
1075641
public function getTime($format = null)
    {
        //argument 1 must be a string or null
        Argument::i()->test(1, 'string', 'null');

        $time = $this->time + $this->offset;

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

        return $time;
    }
65817
public function getCreatedAt($format = null, $timezone = null)
    {
        return $this->getDisplayDateTime($this->created_at, $format, $timezone);
    }
1025564
public static function formatDate($date, $format = 'Y-m-d')
    {
        if (!$date) {
            return null;
        }
        $date = new DateTime($date);
        return $date->format($format);
    }
1218346
public function getFormattedDate($format, $startDate = true)
    {
        $date = $this->getEndDate();

        // Start date should be formatted?
        if ($startDate) {
            $date = $this->getStartDate();
        }

        // Unknown date or format is invalid?
        // Nothing to do
        if (null === $date || !Date::isValidDateFormat($format)) {
            return '';
        }

        return $date->format($format);
    }
752151
public static function getFormattedDateTime(\DateTime $val, string $format = \DateTime::ATOM): string
    {
        return StringHelper::dateFormat($val, $format);
    }
1336896
public function i18n(string $format = '', int $time = 0, bool $utc = false): string
    {
        if (!$format) {
            $format = get_option('date_format');
            $format .= ' '.get_option('time_format');
            $format = $this->c::mbTrim($format);
        }
        $time = $time ? abs($time) : time(); // UTC time.

        // If UTC enabled, leave `$time` as-is.
        // Otherwise, convert it to a local timestamp.
        // This is necessary because `date_i18n()` doesn't do the conversion.
        // The `date_i18n()` function only works w/UTC (by default), if no `$time` is given.
        $time = $utc ? $time : $this->toLocal($time); // Adjusted time, based on `$utc` param.

        if ($utc && preg_match('/(?<!\\\\)[PIOTZe]/u', $format)) {
            // If UTC is enabled and the date format includes a TZ char.
            // Necessary, because `date_i18n()` doesn't handle this properly.
            // `date_i18n()` translates TZ chars into a local timezone regardless.

            // So here, we escape TZ chars and then apply them in UTC.
            $format = preg_replace('/(?<!\\\\)([PIOTZe])/u', '#\\\\${1}', $format);
            return preg_replace_callback('/(#)([PIOTZe])/u', function ($m) use ($time) {
                return gmdate($m[2], $time); // UTC-based TZ chars.
            }, date_i18n($format, $time, $utc));
        }
        return date_i18n($format, $time, $utc);
    }