本文整理汇总了PHP中Nette\Utils\DateTime::createFromFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTime::createFromFormat方法的具体用法?PHP DateTime::createFromFormat怎么用?PHP DateTime::createFromFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Utils\DateTime
的用法示例。
在下文中一共展示了DateTime::createFromFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleUpdateDate
public function handleUpdateDate($firstName, $surName, $mail, $date, $type, $spz, $tel, $carMakes, $carModel, $additionalInfo)
{
if ($this->isAjax()) {
$this->defaults = array('firstName' => $firstName, 'surName' => $surName, 'mail' => $mail, 'date' => $date, 'type' => $type, 'spz' => $spz, 'telNumber' => $tel, 'carMakes' => $carMakes, 'carModel' => $carModel, 'additionalInfo' => $additionalInfo);
$day = date('N', strtotime(str_replace(' ', '', $date)));
$multiplier = 0;
switch ($type) {
case 5:
$multiplier = 1;
break;
case 6:
$multiplier = 3;
break;
case 7:
$multiplier = 3;
break;
}
if ($day != 7) {
$this->timeIntervals = $this->reservationManager->getIntervalsForDay(Nette\Utils\DateTime::createFromFormat('d. m. Y', $date), $multiplier);
} else {
$this->timeIntervals = array(Model\ExceptionMessages::NOT_DEFINED => 'Zavřeno');
}
$this->redrawControl('addReservationSnippet');
}
}
示例2: sinceDate
public function sinceDate($placeId, $date = null, $count = 7)
{
$files = array();
$dir = dir($this->resolveDir($placeId));
if ($dir === false) {
return array();
}
while (false != ($entry = $dir->read())) {
if (strrpos($entry, '.') != 10 || strrchr($entry, '.') != '.tmp') {
continue;
}
// add filename without ext
$files[] = strstr($entry, '.', true);
}
sort($files);
$datePlain = is_int($date) ? date('Y-m-d', $date) : $date;
$pos = 0;
self::binarySearch($datePlain, $files, 'strcmp', $pos);
$selection = array_slice($files, $pos, $count);
$result = array();
foreach ($selection as $item) {
$itemDate = DateTime::createFromFormat('Y-m-d', $item)->getTimestamp();
$result[$itemDate] = $this->forDate($placeId, $item);
}
return $result;
}
示例3: getValue
/**
* Returns date
*
* @return mixed
*/
public function getValue()
{
if (strlen($this->value) > 0) {
return DateTime::createFromFormat($this->format, $this->value);
}
return $this->value;
}
示例4: createFromArray
/**
* @param array $data
* @return Address
*/
public static function createFromArray(array $data)
{
$data['first_seen'] = DateTime::createFromFormat(DateTime::ATOM, $data['first_seen']);
$data['last_seen'] = DateTime::createFromFormat(DateTime::ATOM, $data['last_seen']);
$address = new Address();
$address->data = $data;
return $address;
}
示例5: createFromArray
/**
* @param array $data
* @return Block
*/
public static function createFromArray(array $data)
{
$data['block_time'] = DateTime::createFromFormat(DateTime::ATOM, $data['block_time']);
$data['arrival_time'] = DateTime::createFromFormat(DateTime::ATOM, $data['arrival_time']);
$block = new Block();
$block->data = $data;
return $block;
}
示例6: create
/**
* @return DataGrid
*/
public function create()
{
$grid = $this->gridFactory->create();
$grid->addColumnText("id", "ID");
$grid->addColumnText("name", "Name")->setFilterText();
$grid->addColumnDateTime("date", "Date")->setFilterDate();
$grid->setDataSource([["id" => 1, "name" => "Karel", "date" => DateTime::createFromFormat("d.m.Y", "10.10.2000")], ["id" => 2, "name" => "Pavel", "date" => new DateTime()]]);
return $grid;
}
示例7: __construct
/**
* @param string $email
* @param User|null $sender
*/
public function __construct($email, User $sender = null)
{
$this->setEmail($email);
$this->sender = $sender;
$this->generateToken();
$startDate = \Nette\Utils\DateTime::createFromFormat('!Y-m-d', date('Y-m-d'));
$this->setValidity($startDate);
$this->lastSending = $startDate;
}
示例8: getValue
/**
* Returns control's value.
* @return string
*/
public function getValue()
{
$value = parent::getValue();
// convert to Nette\Utils\DateTime
if ($value && is_string($value)) {
$format = "d.m.Y";
$value = DateTime::createFromFormat($format, $value);
}
return $value ? $value : NULL;
}
示例9: getValue
/**
* Returns date
*
* @return mixed
*/
public function getValue()
{
if (strlen($this->value) > 0) {
$date = DateTime::createFromFormat($this->format, $this->value);
if ($date === FALSE) {
$this->addError($this->getValueErrorMessage());
return FALSE;
}
return $date->setTime(0, 0, 0);
}
return $this->value;
}
示例10: convertToPHPValue
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === NULL) {
return NULL;
} elseif ($value instanceof \DateTime) {
return NetteDateTime::from($value);
}
$val = NetteDateTime::createFromFormat($platform->getDateTimeFormatString(), $value);
if (!$val) {
throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
}
return NetteDateTime::from($val);
}
示例11: formSucceeded
public function formSucceeded(RegistrationForm $form)
{
if ($form['remember']->getValue()) {
$this->user->setExpiration('14 days', false);
} else {
$this->user->setExpiration('20 minutes', true);
}
$date = DateTime::createFromFormat('Y-m-d', date("Y-m-d"));
try {
$this->manager->add($form['username']->getValue(), $form['password']->getValue(), $form['email']->getValue(), $date);
$this->user->login($form['username']->getValue(), $form['password']->getValue());
} catch (Nette\Security\AuthenticationException $e) {
$form->addError($e->getMessage());
}
}
示例12: validateValue
/**
* @Todo Separate this method to some DateTime Utils class
*
* @param string $value
* @param string $pattern
* @return DateTime
* @throws DateTimeParseException
*/
private static function validateValue($value, $pattern)
{
$value = static::strip($value);
if (($parsed = DateTime::createFromFormat($pattern, $value)) === FALSE) {
throw new DateTimeParseException("Value does not match desired format: '{$pattern}'.");
}
$error = DateTime::getLastErrors();
if ($error['error_count'] > 0 || $error['warning_count'] > 0) {
throw new DateTimeParseException('Invalid date given. ' . 'Errors: ' . implode(', ', $error['errors']) . ' ' . 'Warnings: ' . implode(', ', $error['warnings']));
}
$strippedCrossCheckValue = static::strip($parsed->format($pattern));
if ($value !== $strippedCrossCheckValue) {
throw new DateTimeParseException("Invalid date given. Check value does not match original. ['{$strippedCrossCheckValue}' !== '{$value}']");
}
return $parsed;
}
示例13: handleRemoveItem
/**
* @secured
*/
public function handleRemoveItem($day)
{
$this->checkDayValue($day);
try {
$this->itemFacade->removeListingItem($day, $this->listing);
if ($this->presenter->isAjax()) {
$item = new FillingItem(DateTime::createFromFormat('d.m.Y', $day . '.' . $this->listing->getMonth() . '.' . $this->listing->getYear()));
$this['itemsTable']->refreshTable([$item]);
} else {
$this->flashMessage('Řádek byl vymazán.', 'success');
$this->redirect('this');
}
} catch (ListingNotFoundException $lnf) {
$this->flashMessage('Výčetka, kterou se snažíte upravit, nebyla nalezena.');
$this->redirect('Listing:overview');
}
}
示例14: createFromArray
/**
* @param array $data
* @return Transaction
*/
public static function createFromArray(array $data)
{
$transaction = new Transaction();
foreach ($data['inputs'] as $key => $inputData) {
$transaction->inputs[$key] = Input::createFromArray($inputData);
}
foreach ($data['outputs'] as $key => $outputData) {
$transaction->outputs[$key] = Output::createFromArray($outputData);
}
unset($data['inputs']);
unset($data['outputs']);
$data['first_seen_at'] = DateTime::createFromFormat(DateTime::ATOM, $data['first_seen_at']);
$data['last_seen_at'] = DateTime::createFromFormat(DateTime::ATOM, $data['last_seen_at']);
$data['block_time'] = DateTime::createFromFormat(DateTime::ATOM, $data['block_time']);
$transaction->data = $data;
return $transaction;
}
示例15: getValue
/**
* @return DateTime|NULL
*/
public function getValue()
{
if (!($value = $this->value)) {
return NULL;
}
if ($value instanceof \DateTime || is_int($value)) {
return DateTime::from($value);
}
try {
return DateTime::createFromFormat($this->format, $this->value);
} catch (\Exception $e) {
}
if ($time = strtotime($value)) {
return DateTime::from($value);
}
return NULL;
}