public static function fromString($value, array $formats = [])
	{
		$formats = array_merge($formats, [
			'Y-m-d H:i:s.u',
			'Y-m-d H:i:s',
			'Y-m-d',
			'j. n. Y G:i:s',
			'j. n. Y G:i',
			'j. n. Y',
			'U',
		]);

		if ($value instanceof \DateTime) {
			return $value;
		}

		if ($value instanceof \DateTimeImmutable) {
			$date = new \DateTime('now', $value->getTimezone());
			$date->setTimestamp($value->getTimestamp());

			return $date;
		}

		foreach ($formats as $format) {
			if (!is_string($format) || !$date = \DateTime::createFromFormat($format, $value)) {
				continue;
			}

			return $date;
		}

		$timestamp = strtotime($value);

		if ($timestamp !== false) {
			$date = new \DateTime;
			$date->setTimestamp($timestamp);

			return $date;
		}

		throw new DataGridDateTimeHelperException;
	}
public static function fromString($value, array $formats = [])
	{
		$formats = array_merge($formats, [
			'Y-m-d H:i:s.u',
			'Y-m-d H:i:s',
			'Y-m-d',
			'j. n. Y G:i:s',
			'j. n. Y G:i',
			'j. n. Y',
			'U',
		]);

		if ($value instanceof \DateTime) {
			return $value;
		}

		if ($value instanceof \DateTimeImmutable) {
			$date = new \DateTime('now', $value->getTimezone());
			$date->setTimestamp($value->getTimestamp());

			return $date;
		}

		foreach ($formats as $format) {
			if (!is_string($format) || !$date = \DateTime::createFromFormat($format, $value)) {
				continue;
			}

			return $date;
		}

		$timestamp = strtotime($value);

		if ($timestamp !== false) {
			$date = new \DateTime;
			$date->setTimestamp($timestamp);

			return $date;
		}

		throw new DataGridDateTimeHelperException;
	}
public static function fromString ( $ value , array $ formats = [ ] ) { $ formats = array_merge ( $ formats , [ 'Y-m-d H:i:s.u' , 'Y-m-d H:i:s' , 'Y-m-d' , 'j. n. Y G:i:s' , 'j. n. Y G:i' , 'j. n. Y' , 'U' , ] ) ; if ( $ value instanceof \ DateTime ) { return $ value ; } if ( $ value instanceof \ DateTimeImmutable ) { $ date = new \ DateTime ( 'now' , $ value -> getTimezone ( ) ) ; $ date -> setTimestamp ( $ value -> getTimestamp ( ) ) ; return $ date ; } foreach ( $ formats as $ format ) { if ( ! is_string ( $ format ) || ! $ date = \ DateTime :: createFromFormat ( $ format , $ value ) ) { continue ; } return $ date ; } $ timestamp = strtotime ( $ value ) ; if ( $ timestamp !== false ) { $ date = new \ DateTime ; $ date -> setTimestamp ( $ timestamp ) ; return $ date ; } throw new DataGridDateTimeHelperException ; }
Convert string into DateTime object from more date without time
@param  mixed     $value
@param  string[]  $formats
@return \DateTime
@throws DataGridDateTimeHelperException
Convert string into DateTime object from more date without time