當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DateTimeImmutable::createFromFormat方法代碼示例

本文整理匯總了PHP中DateTimeImmutable::createFromFormat方法的典型用法代碼示例。如果您正苦於以下問題:PHP DateTimeImmutable::createFromFormat方法的具體用法?PHP DateTimeImmutable::createFromFormat怎麽用?PHP DateTimeImmutable::createFromFormat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DateTimeImmutable的用法示例。


在下文中一共展示了DateTimeImmutable::createFromFormat方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: isValidDate

 /**
  * {@inheritdoc}
  */
 public function isValidDate($month_day, $month, $year, &$errors = null)
 {
     // Create a DateTime object directly.
     $datetime = \DateTimeImmutable::createFromFormat('n/j/Y', sprintf('%d/%d/%d', $month, $month_day, $year));
     $errors = $datetime->getLastErrors();
     return empty($errors['warning_count']) && empty($errors['error_count']);
 }
開發者ID:hussainweb,項目名稱:date-converter,代碼行數:10,代碼來源:ValidDateTimeCheck.php

示例2: make

 public function make(Str $name, Str $value) : HeaderInterface
 {
     if ((string) $name->toLower() !== 'date') {
         throw new InvalidArgumentException();
     }
     return new Date(new DateValue(\DateTimeImmutable::createFromFormat(\DateTime::RFC1123, (string) $value)));
 }
開發者ID:innmind,項目名稱:http,代碼行數:7,代碼來源:DateFactory.php

示例3: itShouldDeserializeADateTimeImmutable

 /**
  * @test
  */
 public function itShouldDeserializeADateTimeImmutable()
 {
     $customSerializer = new DateTimeCustomSerializer();
     $serialized = [1469787919, new \DateTimeZone('+00:00')];
     $object = $customSerializer->deserialize($serialized, \DateTimeImmutable::class);
     $this->assertEquals($object, \DateTimeImmutable::createFromFormat('U', 1469787919, new \DateTimeZone('+00:00')));
 }
開發者ID:remi-san,項目名稱:serializer,代碼行數:10,代碼來源:DateTimeCustomSerializerTest.php

示例4: createMessageFromArray

 /**
  * @param string $messageName
  * @param array $messageData
  * @throws \UnexpectedValueException
  * @return DomainMessage
  */
 public function createMessageFromArray($messageName, array $messageData)
 {
     if (!class_exists($messageName)) {
         throw new \UnexpectedValueException('Given message name is not a valid class: ' . (string) $messageName);
     }
     if (!is_subclass_of($messageName, DomainMessage::class)) {
         throw new \UnexpectedValueException(sprintf('Message class %s is not a sub class of %s', $messageName, DomainMessage::class));
     }
     if (!isset($messageData['message_name'])) {
         $messageData['message_name'] = $messageName;
     }
     if (!isset($messageData['uuid'])) {
         $messageData['uuid'] = Uuid::uuid4();
     }
     if (!isset($messageData['version'])) {
         $messageData['version'] = 0;
     }
     if (!isset($messageData['created_at'])) {
         $time = microtime(true);
         if (false === strpos($time, '.')) {
             $time .= '.0000';
         }
         $messageData['created_at'] = \DateTimeImmutable::createFromFormat('U.u', $time);
     }
     if (!isset($messageData['metadata'])) {
         $messageData['metadata'] = [];
     }
     return $messageName::fromArray($messageData);
 }
開發者ID:MattKetmo,項目名稱:common,代碼行數:35,代碼來源:FQCNMessageFactory.php

示例5: __invoke

 public function __invoke($value)
 {
     if ($value === NULL) {
         return NULL;
     }
     return \DateTimeImmutable::createFromFormat('U.u', sprintf('%.03f', (double) $value / 1000));
 }
開發者ID:Lesspion,項目名稱:bpmn,代碼行數:7,代碼來源:DateTimeMillisTransformer.php

示例6: _decodeFromDER

 protected static function _decodeFromDER(Identifier $identifier, $data, &$offset)
 {
     $idx = $offset;
     $length = Length::expectFromDER($data, $idx);
     $str = substr($data, $idx, $length->length());
     $idx += $length->length();
     if (!preg_match(self::REGEX, $str, $match)) {
         throw new DecodeException("Invalid GeneralizedTime format.");
     }
     list(, $year, $month, $day, $hour, $minute, $second) = $match;
     if (isset($match[7])) {
         $frac = $match[7];
         // DER restricts trailing zeroes in fractional seconds component
         if ($frac[strlen($frac) - 1] === '0') {
             throw new DecodeException("Fractional seconds must omit trailing zeroes.");
         }
         $frac = (int) $frac;
     } else {
         $frac = 0;
     }
     $time = $year . $month . $day . $hour . $minute . $second . "." . $frac . self::TZ_UTC;
     $dt = \DateTimeImmutable::createFromFormat("!YmdHis.uT", $time, self::_createTimeZone(self::TZ_UTC));
     if (!$dt) {
         throw new DecodeException("Failed to decode GeneralizedTime: " . self::_getLastDateTimeImmutableErrorsStr());
     }
     $offset = $idx;
     return new self($dt);
 }
開發者ID:sop,項目名稱:asn1,代碼行數:28,代碼來源:GeneralizedTime.php

示例7: fromDatabase

 /**
  * {@inheritdoc}
  */
 public function fromDatabase($value)
 {
     if ($this->immutable) {
         return \DateTimeImmutable::createFromFormat($this->format, $value);
     }
     return \DateTime::createFromFormat($this->format, $value);
 }
開發者ID:innmind,項目名稱:neo4j-onm,代碼行數:10,代碼來源:DateType.php

示例8: toItinerary

 /**
  * @param RouteCandidateDto $aRouteCandidate
  * @return Itinerary
  */
 public function toItinerary(RouteCandidateDto $aRouteCandidate)
 {
     $legs = array();
     foreach ($aRouteCandidate->getLegs() as $legDto) {
         $legs[] = new Leg($legDto->getLoadLocation(), $legDto->getUnloadLocation(), \DateTimeImmutable::createFromFormat(\DateTime::ATOM, $legDto->getLoadTime()), \DateTimeImmutable::createFromFormat(\DateTime::ATOM, $legDto->getUnloadTime()));
     }
     return new Itinerary($legs);
 }
開發者ID:josecelano,項目名稱:php-ddd-cargo-sample,代碼行數:12,代碼來源:RouteCandidateDtoAssembler.php

示例9: testCreateFromFormatFailure

 public function testCreateFromFormatFailure()
 {
     $time = 'foo';
     $immutable = DateTimeImmutable::createFromFormat(DateTime::RFC3339, $time);
     $mutable = DateTime::createFromFormat(DateTime::RFC3339, $time);
     $this->assertFalse($immutable);
     $this->assertSame(DateTime::getLastErrors(), DateTimeImmutable::getLastErrors());
 }
開發者ID:comsolit,項目名稱:date-time-immutable,代碼行數:8,代碼來源:DateTimeImmutableTest.php

示例10: __construct

 /**
  * Create a new audi event (timestamp is initialized here).
  * 
  * @param ProcessEngine $engine
  * @param boolean $delay Delay creation of timestamp by 1 millisecond?
  */
 public function __construct(ProcessEngine $engine, $delay = false)
 {
     if ($delay) {
         usleep(1000);
     }
     $this->engine = $engine;
     $this->timestamp = \DateTimeImmutable::createFromFormat('U.u', sprintf('%0.3f', microtime(true)));
 }
開發者ID:Lesspion,項目名稱:bpmn,代碼行數:14,代碼來源:AbstractAuditEvent.php

示例11: dateTime

 /**
  * Get date as a datetime object.
  *
  * @param string $tz Timezone
  * @throws \RuntimeException
  * @return \DateTimeImmutable
  */
 public function dateTime($tz = "UTC")
 {
     $dt = \DateTimeImmutable::createFromFormat("!U", $this->value(), self::_createTimeZone($tz));
     if (false === $dt) {
         throw new \RuntimeException("Failed to create DateTime: " . self::_getLastDateTimeImmutableErrorsStr());
     }
     return $dt;
 }
開發者ID:sop,項目名稱:jwx,代碼行數:15,代碼來源:NumericDateClaim.php

示例12: unserialize

 /**
  * @param $serialized
  * @return Envelope
  */
 public function unserialize($serialized)
 {
     $data = json_decode($serialized, true);
     $messageData = $data['message'];
     $messageData['created_at'] = \DateTimeImmutable::createFromFormat('Y-m-d\\TH:i:s.u', $messageData['created_at'], new \DateTimeZone('UTC'));
     $proophMessage = $this->messageFactory->createMessageFromArray($messageData['message_name'], $messageData);
     $envelope = new Envelope(BernardMessage::fromProophMessage($proophMessage));
     return $envelope;
 }
開發者ID:prooph,項目名稱:psb-bernard-dispatcher,代碼行數:13,代碼來源:BernardSerializer.php

示例13: findByToken

 public function findByToken($accessTokenId)
 {
     $qb = $this->dbalConnection->createQueryBuilder();
     $stmt = $qb->select('*')->from($this->tableConfiguration->getAccessTokenTableName())->where($qb->expr()->like('access_token', ':accessToken'))->setMaxResults(1)->setParameter('accessToken', $accessTokenId)->execute();
     $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     if (1 !== count($rows)) {
         throw new AccessTokenNotFound($accessTokenId);
     }
     return new AccessToken($rows[0]['access_token'], \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $rows[0]['expires_at'], new \DateTimeZone('UTC')), $rows[0]['client_id'], $rows[0]['resource_owner_id'] && $rows[0]['resource_owner_type'] ? new ResourceOwner($rows[0]['resource_owner_id'], $rows[0]['resource_owner_type']) : null, explode(',', $rows[0]['scopes']));
 }
開發者ID:borisguery,項目名稱:oauth2-server-storage-dbal,代碼行數:10,代碼來源:DbalAccessTokenStorage.php

示例14: parseDateTime

 private function parseDateTime($data, array $type)
 {
     $timezone = isset($type['params'][1]) ? new \DateTimeZone($type['params'][1]) : $this->defaultTimezone;
     $format = $this->getFormat($type);
     $datetime = \DateTimeImmutable::createFromFormat($format, (string) $data, $timezone);
     if (false === $datetime) {
         throw new \RuntimeException(sprintf('Invalid datetime "%s", expected format %s.', $data, $format));
     }
     return $datetime;
 }
開發者ID:hellofresh,項目名稱:engine,代碼行數:10,代碼來源:DateTimeImmutableHandler.php

示例15: createFromFormat

 /**
  * @param string $format
  * @param string $time
  * @param \DateTimeZone $timezone
  *
  * @return \Staffim\DateTime\DateTime
  */
 public static function createFromFormat($format, $time, $timezone = null)
 {
     /**
      * @see https://bugs.php.net/bug.php?id=69565
      */
     if ($timezone) {
         return static::createFromNativeDate(parent::createFromFormat($format, $time, $timezone));
     } else {
         return static::createFromNativeDate(parent::createFromFormat($format, $time));
     }
 }
開發者ID:staffim,項目名稱:datetime,代碼行數:18,代碼來源:DateTime.php


注:本文中的DateTimeImmutable::createFromFormat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。