Recebe um date em formato aleatório e retorna um date no padrão informado ou que esta por padrão
@param string $date
@param string $pattern
@return mixed
497613
public function getDateTime(string $date, string $pattern = "Y-m-d H:i:s")
    {
        if (!$date)
            $this->data = date($pattern);
        else
            $this->prepareDateTime($date);

        if($this->erro || !isset($this->data['ano']) || !isset($this->data['mes']) || !isset($this->data['dia'])) {
            return null;
        } else {
            $strtoTime = "";
            if (isset($this->data['h']) && $this->data['h'] > 11) {
                $this->data['h'] -= 12;
                $strtoTime = "+12hours";
            }

            $originalDate = $this->data['ano'] . '-' . $this->data['mes'] . '-' . $this->data['dia'] . " " . ($this->data['h'] ?? 0) . ":" . ($this->data['i'] ?? 0) . ":" . ($this->data['s'] ?? 0);
            return date($pattern, strtotime($originalDate . $strtoTime));
        }
    }
615852
protected function getRegExpForPattern(string $pattern) : string
    {
        $patternReplaced = str_replace(['*', '?'], ["\nA\n", "\nQ\n"], $pattern);
        $patternReplaced = preg_quote($patternReplaced, '/');
        $patternReplaced = str_replace(["\nA\n", "\nQ\n"], ['.*', '.'], $patternReplaced);

        return '/^' . $patternReplaced . '$/';
    }
624980
protected function formatDayInYear($pattern,$date)
	{
		$day=$date['yday'];
		if(($n=strlen($pattern))<=3)
			return str_pad($day,$n,'0',STR_PAD_LEFT);
		else
			throw new CException(Yii::t('yii','The pattern for day in year must be "D", "DD" or "DDD".'));
	}
25762
public static boolean isValid(String date, String pattern) {
        Date d = parseDate(date, pattern);
        return d != null && format(d, pattern).equals(date);
    }
1181067
public function date($date)
    {
        $events = $this->repository->findEventsByDate($date);

        if (empty($events)) {
            abort(404);
        }

        return view('cms-frontend::events.date')->with('events', $events);
    }
1126988
private function parseFormat($format, $date) {
        
        $this->updateJalaliFromGeorgian();
        
        // reverse engineer date formats
        $keys = [
            'Y' => ['year', '\d{4}'],
            'y' => ['year', '\d{2}'],
            'm' => ['month', '\d{2}'],
            'n' => ['month', '\d{1,2}'],
            'M' => ['month', '[A-Z][a-z]{3}'],
            'F' => ['month', '[A-Z][a-z]{2,8}'],
            'd' => ['day', '\d{2}'],
            'j' => ['day', '\d{1,2}'],
            'D' => ['day', '[A-Z][a-z]{2}'],
            'l' => ['day', '[A-Z][a-z]{6,9}'],
            'u' => ['hour', '\d{1,6}'],
            'h' => ['hour', '\d{2}'],
            'H' => ['hour', '\d{2}'],
            'g' => ['hour', '\d{1,2}'],
            'G' => ['hour', '\d{1,2}'],
            'i' => ['minute', '\d{2}'],
            's' => ['second', '\d{2}'],
        ];
        
        // convert format string to regex
        $regex      = '';
        $characters = str_split($format);
        foreach ($characters as $n => $character) {
            $lastCharacter = isset($characters[$n - 1]) ? $characters[$n - 1] : '';
            $skipCurrent   = '\\' == $lastCharacter;
            if ( ! $skipCurrent && isset($keys[$character])) {
                $regex .= '(?P<' . $keys[$character][0] . '>' . $keys[$character][1] . ')';
            } else {
                if ('\\' == $character) {
                    $regex .= $character;
                } else {
                    $regex .= preg_quote($character);
                }
            }
        }
        
        $sections = [];
        // now try to match it
        if (preg_match('#^' . $regex . '$#', $date, $sections)) {
            foreach ($sections as $k => $v) {
                if (is_int($k)) {
                    unset($sections[$k]);
                }
            }
        } else {
            throw new InvalidArgumentException('the given date is not valid through the given format.');
        }
        
        $yearToSet = $this->year;
        if (isset($sections['year'])) {
            
            $yearToSet = $sections['year'];
            
            // checking to make the year absolute
            if (strlen($yearToSet) == 2) {
                $instance  = static::now();
                $yearToSet += (int) ($instance->format('Y') - $instance->format('y'));
            }
        }
        $monthToSet = $this->month;
        if (isset($sections['month'])) {
            $monthToSet = $sections['month'];
        }
        $dayToSet = $this->day;
        if (isset($sections['day'])) {
            $dayToSet = $sections['day'];
            
            //there's an exception
            $max = static::getMonthLength($monthToSet, $yearToSet);
            if ($dayToSet > $max) {
                throw new InvalidArgumentException('the current month maximum days is ' . $max);
            }
        }
        $hourToSet = $this->hour;
        if (isset($sections['hour'])) {
            $hourToSet = $sections['hour'];
        }
        $minuteToSet = $this->minute;
        if (isset($sections['minute'])) {
            $minuteToSet = $sections['minute'];
        }
        $secondToSet = $this->second;
        if (isset($sections['second'])) {
            $secondToSet = $sections['second'];
        }
        
        $this->setDateTime($yearToSet, $monthToSet, $dayToSet, $hourToSet, $minuteToSet, $secondToSet);
        
        $this->updateGeorgianFromJalali();
        
    }
476731
public static Date parseDate(final String date, final List<String> patterns)
	{
		for (final String pattern : patterns)
		{
			final SimpleDateFormat formatter = new SimpleDateFormat(pattern);
			try
			{
				return formatter.parse(date);
			}
			catch (final ParseException e)
			{
				// Do nothing...
			}
		}
		return null;
	}
535651
static protected function regex($date)
    {
      if(!preg_match('/^' . self::PATTERN . '$/', $date, $matches))
        throw new InvalidArgumentException(__METHOD__ . '; Invalid date, no match with pattern (' . $date . ')');
        
      return $matches;
    }
877755
public function messageHistory($date) {
        try{
            if(empty($date))
                throw new Exception('时间不能为空');
            $ret = $this->curl('/message/history', array('date' => $date));
            if(empty($ret))
                throw new Exception('请求失败');
            return $ret;
        }catch (Exception $e) {
            print_r($e->getMessage());
        }
    }
152185
protected function getLogOrFail($date)
    {
        $log = null;

        try {
            $log = $this->logViewer->get($date);
        }
        catch (LogNotFoundException $e) {
            abort(404, $e->getMessage());
        }

        return $log;
    }
841375
public static Date formatDate(Date orig, String... patterns) {
        String pattern = TIMESTAMP_PATTERN;
        if (patterns != null && patterns.length > 0
                && StringUtils.isNotBlank(patterns[0])) {
            pattern = patterns[0];
        }
        return parseDate(DateFormatUtils.format(orig, pattern));
    }
1177076
public function readWithPattern($text, $pattern) {
		$pieces = explode("\n", $text);
		$result = [];
		foreach ($pieces as $piece) {
			$result[] = sscanf(trim($piece, "\r\n"), $pattern);
		}
		return $result;
	}
910374
public static String format(Date date, String pattern) {
		return new DateTime(date.getTime()).toString(pattern);
	}
681352
public static function DateFormat($format, $date = null)
  {
    if (!empty($date) && !is_int($date)) {
      $date = strtotime($date);
    }

    return strftime($format, $date ?: time());
  }
759832
public function select(string $pattern): \Iterator
    {
        //游标,每次查询必须从0开始
        $iterator = NULL;
        while (true) {
            //查询并更新游标
            $ret = $this->handle->zScan($this->name, $iterator, $pattern, 10);

            //没有更多数据了
            if (false === $ret) {
                break;
            }

            //逐个返回
            foreach ($ret as $key => $val) {
                yield [$key => $val];
            }
        }
    }
929128
public function dateFormat($date, $format = '%e %b %Y')
    {
        if ($date instanceof \DateTime) {
            $ts = $date->getTimestamp();
        } elseif (is_numeric($date)) {
            $ts = $date;
        } elseif (preg_match('/^[0-9]{4,4}-[0-9]{2,2}-[0-9]{2,2}T[0-9]{2,2}:[0-9]{2,2}.*/', $date)) {
            // timestamp format 2013-01-01T00:00:00
            $ts = new \DateTime($date);
            $ts = $ts->getTimestamp();
        } else {
            throw new \InvalidArgumentException(sprintf("Cannot format %s as a date", $date));
        }

        return strftime($format, $ts);
    }
1313596
public static String format(Locale locale, TimeZone timeZone, String pattern, Date date) {
	synchronized (data) {
	    String key = locale.toString() + '-' + timeZone.getID() + '-' + pattern;
	    Object obj = data.get(key);
	    if (obj != null) {
		return ((SimpleDateFormat) obj).format(date);
	    }
	    SimpleDateFormat sdf = new SimpleDateFormat(pattern, locale);
	    sdf.setTimeZone(timeZone);
	    data.put(key, sdf);
	    return sdf.format(date);
	}
    }