本文整理汇总了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;
}
示例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);
}
示例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']));
}
示例4: getDate
protected function getDate(\DateTimeInterface $date = null)
{
if ($date === null) {
return str_repeat('0', 8);
}
return $date->format('dmY');
}
示例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);
}
示例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;
}
示例7: writeLastModified
private function writeLastModified(\XMLWriter $xmlWriter, \DateTimeInterface $lastModified = null)
{
if ($lastModified === null) {
return;
}
$xmlWriter->startElement('lastmod');
$xmlWriter->text($lastModified->format('c'));
$xmlWriter->endElement();
}
示例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;
}
示例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'));
}
}
示例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));
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}