当前位置: 首页>>代码示例>>PHP>>正文


PHP DateTimeInterface::format方法代码示例

本文整理汇总了PHP中DateTimeInterface::format方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeInterface::format方法的具体用法?PHP DateTimeInterface::format怎么用?PHP DateTimeInterface::format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DateTimeInterface的用法示例。


在下文中一共展示了DateTimeInterface::format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: findListDatesWithin

 /**
  * @param \DateTimeInterface $dateStart
  * @param \DateTimeInterface $dateEnd
  * @return \DateTime[]
  */
 public function findListDatesWithin(\DateTimeInterface $dateStart, \DateTimeInterface $dateEnd)
 {
     $yearStart = $dateStart->format('Y-m-d');
     $yearEnd = $dateEnd->format('Y-m-d');
     $dayStart = $dateStart->format('Y-m-d');
     $dayEnd = $dateEnd->format('Y-m-d');
     $qb = $this->createQueryBuilder('f')->where("f.annee >= :yearStart AND f.annee <= :yearEnd")->orderBy("f.annee");
     $qb->setParameter(':yearStart', $yearStart)->setParameter(':yearEnd', $yearEnd);
     $rows = $qb->getQuery()->getResult();
     if (is_null($rows)) {
         return array();
     }
     /**
      * @var \WCS\CantineBundle\Entity\Feries $dayOff
      */
     $result = [];
     foreach ($rows as $dayOff) {
         // the order is important !
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getJourAn', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getPaques', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getFeteTravail', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getHuitMai', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getAscension', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getVendrediAscension', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getPentecote', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getFeteNational', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getAssomption', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getToussaint', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getArmistice', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getNoel', $result);
     }
     return $result;
 }
开发者ID:WildCodeSchool,项目名称:projet-gesty,代码行数:38,代码来源:FeriesRepository.php

示例2: serializeDateTimeImmutable

 public function serializeDateTimeImmutable(VisitorInterface $visitor, \DateTimeInterface $date, array $type, Context $context)
 {
     if ($visitor instanceof XmlSerializationVisitor && false === $this->xmlCData) {
         return $visitor->visitSimpleString($date->format($this->getFormat($type)), $type, $context);
     }
     return $visitor->visitString($date->format($this->getFormat($type)), $type, $context);
 }
开发者ID:hellofresh,项目名称:engine,代码行数:7,代码来源:DateTimeImmutableHandler.php

示例3: tag

 public function tag(\DateTimeInterface $date)
 {
     $this->getDay->bindValue(':datum', $date->format('Y-m-d'));
     $this->getDay->execute();
     $columns = $this->getDay->fetch(\PDO::FETCH_ASSOC);
     if ($columns === false) {
         $columns = array('status' => $date->format('N') >= 6 ? Status::WOCHENENDE : Status::FREI, 'beginn' => $date->format('Y-m-d'), 'ende' => $date->format('Y-m-d'));
     }
     return new Tag(new Status($columns['status']), new \DateTimeImmutable($columns['beginn']), new \DateTimeImmutable($columns['ende']));
 }
开发者ID:HoffmannP,项目名称:Arbeitszeitkonto,代码行数:10,代码来源:Arbeitszeitkonto.class.php

示例4: getDate

 protected function getDate(\DateTimeInterface $date = null)
 {
     if ($date === null) {
         return str_repeat('0', 8);
     }
     return $date->format('dmY');
 }
开发者ID:forward-hkg,项目名称:tikon-generator,代码行数:7,代码来源:TikonGenerator.php

示例5: formatExample

 /**
  * Creates an example for a date format.
  *
  * This is centralized for a consistent method of creating these examples.
  *
  * @param string $format
  *
  * @return string
  */
 public static function formatExample($format)
 {
     if (!static::$dateExample) {
         static::$dateExample = new DrupalDateTime();
     }
     return static::$dateExample->format($format);
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:16,代码来源:Datetime.php

示例6: getQueryEleveIdsInscritsVoyage

 /**
  * renvoit la requete suivante :
  * tous les ids des eleves INSCRITS en voyage scolaire (non annulée)
  * à la date donnée
  *
  * @param \DateTimeInterface $date_day
  *
  * @return QueryBuilder
  */
 protected function getQueryEleveIdsInscritsVoyage(\DateTimeInterface $date_day)
 {
     $query = $this->getEntityManager()->createQueryBuilder()->select('DISTINCT eleve_inscrit.id')->from('WCSCantineBundle:Eleve', 'eleve_inscrit')->join('eleve_inscrit.voyages', 'voyage_scolaire')->where('voyage_scolaire.estAnnule = FALSE')->andWhere(':date_day BETWEEN 
                     DATE(voyage_scolaire.date_debut) 
                     AND 
                     DATE(voyage_scolaire.date_fin)')->setParameter(':date_day', $date_day->format('Y-m-d'));
     return $query;
 }
开发者ID:WildCodeSchool,项目名称:projet-gesty,代码行数:17,代码来源:ActivityRepositoryAbstract.php

示例7: writeLastModified

 private function writeLastModified(\XMLWriter $xmlWriter, \DateTimeInterface $lastModified = null)
 {
     if ($lastModified === null) {
         return;
     }
     $xmlWriter->startElement('lastmod');
     $xmlWriter->text($lastModified->format('c'));
     $xmlWriter->endElement();
 }
开发者ID:refinery29,项目名称:sitemap,代码行数:9,代码来源:SitemapWriter.php

示例8: setDateTime

 /**
  * Set the date-time of the Date in this Header.
  *
  * If a DateTime instance is provided, it is converted to DateTimeImmutable.
  *
  * @param DateTimeInterface $dateTime
  */
 public function setDateTime(DateTimeInterface $dateTime)
 {
     $this->clearCachedValueIf($this->getCachedValue() != $dateTime->format(DateTime::RFC2822));
     if ($dateTime instanceof DateTime) {
         $immutable = new DateTimeImmutable('@' . $dateTime->getTimestamp());
         $dateTime = $immutable->setTimezone($dateTime->getTimezone());
     }
     $this->dateTime = $dateTime;
 }
开发者ID:tweakers-dev,项目名称:swiftmailer,代码行数:16,代码来源:DateHeader.php

示例9: __construct

 /**
  * @inheritdoc
  */
 public function __construct(\DateTimeInterface $firstDate, \DateTimeInterface $lastDate, $description = '')
 {
     $this->firstDate = new \DateTimeImmutable($firstDate->format('Y-m-d H:i:s'));
     $this->lastDate = new \DateTimeImmutable($lastDate->format('Y-m-d H:i:s'));
     $this->description = $description;
     if ($this->firstDate > $this->lastDate) {
         throw new \LogicException('The first date must be lower than the last date (first date : ' . $this->firstDate->format('Y-m-d') . ' last date : ' . $this->lastDate->format('Y-m-d'));
     }
 }
开发者ID:WildCodeSchool,项目名称:projet-gesty,代码行数:12,代码来源:Period.php

示例10: setValue

 /**
  * @param \DateTimeInterface|NULL $value
  * @return \Nella\Forms\DateTime\DateInput
  */
 public function setValue($value = NULL)
 {
     if ($value === NULL) {
         return parent::setValue(NULL);
     } elseif (!$value instanceof \DateTimeInterface) {
         throw new \Nette\InvalidArgumentException('Value must be DateTimeInterface or NULL');
     }
     return parent::setValue($value->format($this->format));
 }
开发者ID:nella,项目名称:forms-datetime,代码行数:13,代码来源:DateInput.php

示例11: formatDate

 protected function formatDate(\DateTimeInterface $value, $nestingLevel)
 {
     $seconds = (int) $value->format('U');
     $milliseconds = (int) $value->format('u') / 1000;
     if ($seconds < 0) {
         return new UTCDateTime($seconds * 1000 - $milliseconds);
     } else {
         return new UTCDateTime($seconds * 1000 + $milliseconds);
     }
 }
开发者ID:acrobat,项目名称:monolog,代码行数:10,代码来源:MongoDBFormatter.php

示例12: getSerializedEvent

 /**
  * @return \stdClass
  */
 private function getSerializedEvent()
 {
     $eventObj = new \stdClass();
     $eventObj->event = $this->type;
     $eventObj->source = $this->serializedSource;
     $eventObj->target = $this->serializedTarget;
     $eventObj->target_object = $this->serializedTargetObject;
     $eventObj->created_at = $this->date->format(TwitterDate::FORMAT);
     return $eventObj;
 }
开发者ID:remi-san,项目名称:twitter,代码行数:13,代码来源:EventSerializerTest.php

示例13: getHolidays

 /**
  * @param null|\DateTimeInterface $dateTime
  * @param null|string $division
  * @return null|\stdClass[]
  * @throws \Exception
  */
 public static function getHolidays(\DateTimeInterface $dateTime = null, $division = null)
 {
     self::loadHolidayData();
     /** @var \stdClass $events */
     $events = self::filterByDivision($division);
     if (!$dateTime) {
         return $events;
     }
     /** @var string $dateKey */
     $dateKey = $dateTime->format('Y-m-d');
     return isset($events[$dateKey]) ? $events[$dateKey] : null;
 }
开发者ID:6by6,项目名称:uk-bank-holidays,代码行数:18,代码来源:Feed.php

示例14: getSerializedDirectMessage

 /**
  * @return \stdClass
  */
 private function getSerializedDirectMessage()
 {
     $dmObj = new \stdClass();
     $dmObj->id = $this->id;
     $dmObj->sender = $this->serializedSender;
     $dmObj->recipient = $this->serializedRecipient;
     $dmObj->text = $this->text;
     $dmObj->created_at = $this->date->format(TwitterDate::FORMAT);
     $dmObj->entities = $this->serializedEntities;
     $superDmObject = new \stdClass();
     $superDmObject->direct_message = $dmObj;
     return $superDmObject;
 }
开发者ID:remi-san,项目名称:twitter,代码行数:16,代码来源:DirectMessageSerializerTest.php

示例15: getSchoolYearIncluding

 /**
  * @param \DateTimeInterface $date
  * @return null|Period
  * @throws \Doctrine\ORM\NonUniqueResultException
  */
 public function getSchoolYearIncluding(\DateTimeInterface $date)
 {
     $result = $this->getEntityManager()->createQuery('
         SELECT s
         FROM WCSCantineBundle:SchoolYear s 
         WHERE DATE(s.dateStart) < :date_day
         AND DATE(s.dateEnd) > :date_day
     ')->setParameter(':date_day', $date->format('Y-m-d'))->getOneOrNullResult();
     if ($result) {
         return new Period($result->getDateStart(), $result->getDateEnd());
     }
     return null;
 }
开发者ID:WildCodeSchool,项目名称:projet-gesty,代码行数:18,代码来源:SchoolYearRepository.php


注:本文中的DateTimeInterface::format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。