当前位置: 首页>>代码示例>>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;未经允许,请勿转载。