Verifies if the provided date string is in the given format

@param string $datetime
@param string $format

@return boolean
199243
public static function verifyDateTime(string $datetime, string $format): bool
    {
        $formatted = DateTime::createFromFormat($format, $datetime);

        $errors = DateTime::getLastErrors();

        if (!empty($errors['warning_count'])) {
            return false;
        }

        return $formatted !== false;
    }
763497
public static function parseFormat($format,$datetime, $timezone = null) {
        $datetime = str_replace(self::$monthYear, range(1,12), $datetime);

        $parse = date_parse_from_format($format, $datetime);
        if($parse['error_count'] == 0 && self::isValideDate($parse['year'], $parse['month'], $parse['day']) && self::isValideTime($parse['hour'], $parse['minute'], $parse['second'])){
            list($year, $month, $day) = self::getGregorian($parse['year'], $parse['month'], $parse['day']);
            list($hour,$minute, $second) = array($parse['hour'], $parse['minute'], $parse['second']);

            $timezone = self::createTimeZone($timezone);
            $datetime = new DateTime(sprintf('%04s-%02s-%02s %02s:%02s:%02s', $year, $month, $day, $hour, $minute, $second), $timezone);
            return new static($datetime);
        }
        else{
            throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
        }
    }
1304059
public static function isSupportedFormat($format): bool
    {
        if ($format) {
            return self::isJpeg($format) || self::isPng($format) || self::isGif($format);
        }

        return false;
    }
599308
public static function isValidDateFormat($format)
    {
        if (empty($format) || !is_string($format)) {
            return false;
        }

        $formatted = (new DateTime())->format($format);

        // Formatted date it's the format who is validated?
        // The format is invalid
        if ($formatted === $format) {
            return false;
        }

        // Validate the format used to create the datetime
        $fromFormat = DateTime::createFromFormat($format, $formatted);

        // It's instance of DateTime?
        // The format is valid
        if ($fromFormat instanceof DateTime) {
            return true;
        }

        return $fromFormat instanceof DateTime;
    }
681352
public static function DateFormat($format, $date = null)
  {
    if (!empty($date) && !is_int($date)) {
      $date = strtotime($date);
    }

    return strftime($format, $date ?: time());
  }
170565
protected function formatDateTime($format, $time = 'now', $timestamp = false)
    {
        if (empty($time)) {
            return;
        }

        if (false === $format) {
            return $time;
        } elseif (false !== strpos($format, '\\')) {
            return new $format($time);
        }

        if ($timestamp) {
            $dateTime = new DateTime();
            $dateTime->setTimestamp($time);
        } else {
            $dateTime = new DateTime($time);
        }

        return $dateTime->format($format);
    }
797118
protected function isValidFormat($format)
	{
		return in_array($format, array(self::WEBP_FORMAT_SIMPLE, self::WEBP_FORMAT_LOSSLESS, self::WEBP_FORMAT_EXTENDED));
	}
1159764
public static function isValidDate($date, $formats = array('Y-m-d')) {
		$unixTime = strtotime($date);
		if (!$unixTime) { //strtotime转换不对，日期格式显然不对。
			return false;
		}
	
		//校验日期的有效性，只要满足其中一个格式就OK
		foreach ($formats as $format) {
			if (date($format, $unixTime) == $date) {
				return true;
			}
		}
		
		return false;
	}
493777
public function formatDate(\DateTime $datetime, $format, $useOffset = null)
    {
        if (is_null($useOffset)) {
            $useOffset = $this->getParameter('nyroDev_utility.dateFormatUseOffsetDefault');
        }

        $offset = 0;
        if ($useOffset) {
            $tz = new \DateTimeZone(date_default_timezone_get());
            $offset = -1 * $tz->getOffset($datetime) + $datetime->getOffset();
        }

        return strftime($this->trans($format), $datetime->getTimestamp() + $offset);
    }
686262
public static function formatDate( $datetime, $format = 'Y-m-d H:i' )
	{
		$outputStr = '';
		try {
			if (empty($datetime)) {
				throw new \Exception("datetime param cannot be empty");
			}
			$dateObj = new \DateTime($datetime);
			$outputStr = $dateObj->format($format);
		}
		catch (\Exception $e) {
			$outputStr = '';
		}
		return $outputStr;
	}
411856
public function containsExclusive(DateTime $dateTime) : bool
    {
        return $this->start->comesBefore($dateTime) && $this->end->comesAfter($dateTime);
    }
457932
public function formatDate($format, \DateTime $date = null)
    {
        if (null === $date) {
            return null;
        }

        return $date->format($format);
    }
748707
public static function getFormattedDate($date, $format)
    {
        if (StringUtils::isEmpty($date) || StringUtils::isEmpty($format)) {
            return null;
        }

        return date($format, strtotime($date));
    }
257176
public function format(string $format) : string
    {
        $format = $this->escapeUnapplicableFormatChars($format);

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

        return $this->dateTime->format($format);
    }
528857
public function formatDateTime(\DateTime $datetime, $format, $calendar = \IntlDateFormatter::GREGORIAN)
    {
        $types = array(
            \IntlDateFormatter::NONE,
            \IntlDateFormatter::NONE,
        );
        if (is_array($format)) {
            if (isset($format[0])) {
                $types[0] = $format[0];
            }
            if (isset($format[1])) {
                $types[1] = $format[1];
            }
            $pattern = null;
        } else {
            $pattern = $format;
        }
        $formatter = new \IntlDateFormatter(
            $this->currentLocale,
            $types[0],
            $types[1],
            $datetime->getTimezone()->getName(),
            $calendar,
            $pattern
        );
        return $formatter->format($datetime);
    }
677607
public static function date($format = "Y-m-d H:i:s", $time = null)
    {
        $time = ($time !== null ? $time : time());

        if (!is_numeric($time)) {
            $time = static::toUnix($time);
        }

        return date($format, $time);
    }