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


PHP DateTimeImmutable::format方法代码示例

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


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

示例1: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Starting...');
     $output->writeln('Getting disrupted lines...');
     $lines = $this->getContainer()->get('console.services.line')->findAllDisrupted();
     $count = $lines->getResultCount();
     $output->writeln($count . ' disrupted lines');
     $now = new \DateTimeImmutable();
     if ($count > 0) {
         $lines = $lines->getDomainModels();
         $day = (int) $now->format('N');
         $hour = (int) $now->format('H');
         foreach ($lines as $line) {
             $output->writeln('Getting relevant subscriptions for ' . $line->getName() . ' on day ' . $day . ', hour ' . $hour . '...');
             $subscriptions = $this->getContainer()->get('console.services.subscription')->findAllForLineAndHour($line, $day, $hour);
             $scount = $subscriptions->getResultCount();
             $output->writeln($scount . ' subscriptions found');
             if ($scount > 0) {
                 $title = $line->getStatusSummary();
                 $this->notify($line, $title, $subscriptions->getDomainModels());
                 $output->writeln('Notified ' . $line->getName() . ': ' . $title);
                 // if we sent out some notifications, sleep for 2 seconds before sending more
                 sleep(2);
             }
         }
     }
     $output->writeln('Done');
 }
开发者ID:djmarland,项目名称:tube,代码行数:28,代码来源:StatusHourlyCommand.php

示例2: testResponseToPropertiesTimestampValue

 public function testResponseToPropertiesTimestampValue()
 {
     $date = new \DateTimeImmutable();
     $data = ['foo' => ['timestampValue' => $date->format(self::DATE_FORMAT)]];
     $res = $this->mapper->responseToEntityProperties($data)['properties'];
     $this->assertInstanceOf(\DateTimeImmutable::class, $res['foo']);
     $this->assertEquals($date->format('c'), $res['foo']->format('c'));
 }
开发者ID:GoogleCloudPlatform,项目名称:gcloud-php,代码行数:8,代码来源:EntityMapperTest.php

示例3: toString

 public function toString() : string
 {
     if ($this->expiry instanceof \DateTimeImmutable) {
         $rawToken = $this->token . self::DELIMITER . $this->expiry->format(self::DATE_FORMAT);
     } else {
         $rawToken = $this->token;
     }
     return base64_encode($rawToken);
 }
开发者ID:icehawk,项目名称:forms,代码行数:9,代码来源:Token.php

示例4:

 /**
  * @test
  */
 function it_creates_a_new_message_from_array_and_fqcn()
 {
     $uuid = Uuid::uuid4();
     $createdAt = new \DateTimeImmutable();
     $command = $this->messageFactory->createMessageFromArray(DoSomething::class, ['uuid' => $uuid->toString(), 'version' => 1, 'payload' => ['command' => 'payload'], 'metadata' => ['command' => 'metadata'], 'created_at' => $createdAt->format(\DateTime::ISO8601)]);
     $this->assertEquals(DoSomething::class, $command->messageName());
     $this->assertEquals($uuid->toString(), $command->uuid()->toString());
     $this->assertEquals($createdAt->format(\DateTime::ISO8601), $command->createdAt()->format(\DateTime::ISO8601));
     $this->assertEquals(1, $command->version());
     $this->assertEquals(['command' => 'payload'], $command->payload());
     $this->assertEquals(['command' => 'metadata'], $command->metadata());
 }
开发者ID:archcidburnziso,项目名称:common,代码行数:15,代码来源:FQCNMessageFactoryTest.php

示例5: calculateCalendarMonths

 private function calculateCalendarMonths()
 {
     $months = ((int) $this->date->format('Y') - (int) $this->baseDate->format('Y')) * 12;
     $months += (int) $this->date->format('m') - (int) $this->baseDate->format('m');
     if ($this->date > $this->baseDate) {
         return $months + ($this->date->format('d') < $this->baseDate->format('d') ? -1 : 0);
     } else {
         if ($this->date < $this->baseDate) {
             return $months + ($this->date->format('d') > $this->baseDate->format('d') ? 1 : 0);
         }
     }
     return $months;
 }
开发者ID:wookieb,项目名称:relative-date,代码行数:13,代码来源:DateDiffRequest.php

示例6: hourAction

 public function hourAction()
 {
     //Define your file path based on the cache one
     $filename = $this->container->getParameter('kernel.cache_dir') . '/timestamps/hour.txt';
     $data = @file_get_contents($filename);
     $now = new \DateTimeImmutable();
     $min = (int) $now->format('i');
     $timestamp = $now->getTimestamp();
     $last = (int) $data ?? 0;
     $diff = $timestamp - $last;
     // can only run in the first 5 mins of an hour,
     // and cannot run again within 10 mins
     $withinMin = $min <= 5;
     if ($withinMin && $diff > 10 * 60) {
         $command = new StatusHourlyCommand();
         $command->setContainer($this->container);
         $input = new ArrayInput([]);
         $output = new NullOutput();
         $resultCode = $command->run($input, $output);
         //Create your own folder in the cache directory
         $fs = new Filesystem();
         $fs->mkdir(dirname($filename));
         file_put_contents($filename, $timestamp);
     } else {
         $resultCode = 1;
     }
     return new JsonResponse((object) ['status' => $resultCode, 'diff' => $diff, 'inWindow' => $withinMin]);
 }
开发者ID:djmarland,项目名称:tube,代码行数:28,代码来源:UpdateController.php

示例7: testTransformDateTimeImmutable

 public function testTransformDateTimeImmutable()
 {
     $transformer = new DateTimeToTimestampTransformer('Asia/Hong_Kong', 'America/New_York');
     $input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
     $output = $input->format('U');
     $input = $input->setTimezone(new \DateTimeZone('Asia/Hong_Kong'));
     $this->assertEquals($output, $transformer->transform($input));
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:8,代码来源:DateTimeToTimestampTransformerTest.php

示例8: addCookie

 /**
  * @param Response $response
  * @param string $cookieName
  * @param string $cookieValue
  * @return Response
  */
 public static function addCookie(Response $response, $cookieName, $cookieValue)
 {
     $expirationMinutes = 10;
     $expiry = new \DateTimeImmutable('now + ' . $expirationMinutes . 'minutes');
     $cookie = urlencode($cookieName) . '=' . urlencode($cookieValue) . '; expires=' . $expiry->format(\DateTime::COOKIE) . '; Max-Age=' . $expirationMinutes * 60 . '; path=/; secure; httponly';
     $response = $response->withAddedHeader('Set-Cookie', $cookie);
     return $response;
 }
开发者ID:inkstudiocompany,项目名称:mastertk,代码行数:14,代码来源:Cookie.php

示例9: getFieldBody

 /**
  * Get the string value of the body in this Header.
  *
  * This is not necessarily RFC 2822 compliant since folding white space will
  * not be added at this stage (see {@link toString()} for that).
  *
  * @see toString()
  *
  * @return string
  */
 public function getFieldBody()
 {
     if (!$this->getCachedValue()) {
         if (isset($this->dateTime)) {
             $this->setCachedValue($this->dateTime->format(DateTime::RFC2822));
         }
     }
     return $this->getCachedValue();
 }
开发者ID:tweakers-dev,项目名称:swiftmailer,代码行数:19,代码来源:DateHeader.php

示例10: postUp

 public function postUp(Schema $schema)
 {
     $lineData = [['bakerloo-line', 'bakerloo', 'Bakerloo', 'Bakerloo Line'], ['central-line', 'central', 'Central', 'Central Line'], ['circle-line', 'circle', 'Circle', 'Circle Line'], ['district-line', 'district', 'District', 'District Line'], ['hammersmith-city-line', 'hammersmith-city', 'Hammersmith & City', 'Hammersmith & City Line'], ['jubilee-line', 'jubilee', 'Jubilee', 'Jubilee Line'], ['metropolitan-line', 'metropolitan', 'Metropolitan', 'Metropolitan Line'], ['northern-line', 'northern', 'Northern', 'Northern Line'], ['piccadilly-line', 'piccadilly', 'Piccadilly', 'Piccadilly Line'], ['victoria-line', 'victoria', 'Victoria', 'Victoria Line'], ['waterloo-city-line', 'waterloo-city', 'Waterloo & City', 'Waterloo & City Line'], ['dlr', 'dlr', 'DLR', 'DLR'], ['london-overground', 'london-overground', 'London Overground', 'London Overground'], ['tfl-rail', 'tfl-rail', 'TFL Rail', 'TFL Rail']];
     $now = new \DateTimeImmutable();
     $iso = $now->format('c');
     foreach ($lineData as $i => $line) {
         $this->addSql('INSERT INTO `tube_lines` (url_key, tfl_key, short_name, name, display_order, created_at, updated_at) VALUES (?,?,?,?,?,?,?)', [$line[0], $line[1], $line[2], $line[3], $i + 1, $iso, $iso]);
     }
 }
开发者ID:djmarland,项目名称:tube,代码行数:9,代码来源:Version20151212164332.php

示例11: generate

 /**
  * @param int $fromTs
  * @param int $toTs
  *
  * @return \Generator
  */
 public static function generate($fromTs, $toTs)
 {
     $firstDay = new \DateTimeImmutable(date('Y-m-d', $fromTs));
     $lastDay = new \DateTimeImmutable(date('Y-m-d', $toTs));
     $cursor = new \DateTime($lastDay->format('Y-m-d'));
     while ($cursor >= $firstDay) {
         (yield $cursor->format('Y-m-d'));
         $cursor->sub(new \DateInterval('P1D'));
     }
 }
开发者ID:jiangyu7408,项目名称:notification,代码行数:16,代码来源:CalendarDayGenerator.php

示例12: testDisplayValueForDateTimeImmutable

 public function testDisplayValueForDateTimeImmutable()
 {
     if (PHP_VERSION_ID < 50500) {
         $this->markTestSkipped('\\DateTimeImmutable was introduced in PHP 5.5');
     }
     $now = new \DateTimeImmutable();
     $column = new DateTimeColumn();
     $column->setFormat('Y-m-d H:i:s');
     $this->assertEquals($now->format('Y-m-d H:i:s'), $column->getDisplayedValue($now));
 }
开发者ID:qferr,项目名称:APYDataGridBundle,代码行数:10,代码来源:DateTimeColumnTest.php

示例13: build

 /**
  * Builds the cookie into a HTTP response header.
  *
  * @return string
  */
 public function build() : string
 {
     $str = urlencode($this->name()) . '=' . urlencode($this->value());
     if ($this->expiration) {
         $str .= '; expires=' . $this->expiration->format(\DateTime::COOKIE);
     }
     if (isset($this->attributes[CookieInterface::ATTR_PATH])) {
         $str .= '; path=' . $this->attributes[CookieInterface::ATTR_PATH];
     }
     if (isset($this->attributes[CookieInterface::ATTR_DOMAIN])) {
         $str .= '; domain=' . $this->attributes[CookieInterface::ATTR_DOMAIN];
     }
     if (isset($this->attributes[CookieInterface::ATTR_SECURE]) && $this->attributes[CookieInterface::ATTR_SECURE] === true) {
         $str .= '; secure';
     }
     if (isset($this->attributes[CookieInterface::ATTR_HTTP]) && $this->attributes[CookieInterface::ATTR_HTTP] === true) {
         $str .= '; httponly';
     }
     return $str;
 }
开发者ID:Trivivium,项目名称:Hydro,代码行数:25,代码来源:Cookie.php

示例14: testTransformDateTimeImmutable

 public function testTransformDateTimeImmutable()
 {
     if (PHP_VERSION_ID < 50500) {
         $this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
     }
     $transformer = new DateTimeToTimestampTransformer('Asia/Hong_Kong', 'America/New_York');
     $input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
     $output = $input->format('U');
     $input = $input->setTimezone(new \DateTimeZone('Asia/Hong_Kong'));
     $this->assertEquals($output, $transformer->transform($input));
 }
开发者ID:Aryellix,项目名称:scrumator,代码行数:11,代码来源:DateTimeToTimestampTransformerTest.php

示例15: getListingsOf

 /**
  * @param Channel $channel
  * @param \DateTimeImmutable $specifiedDate
  * @return array
  */
 public function getListingsOf(Channel $channel, \DateTimeImmutable $specifiedDate)
 {
     $criteria = array('channel' => array('builder' => function ($alias) {
         return sprintf("%s.channel", $alias);
     }, 'value' => $channel), 'programDate' => array('builder' => function ($alias) {
         return sprintf("DATE(%s.programDate)", $alias);
     }, 'value' => $specifiedDate->format('Y-m-d')), 'orderBy' => array('builder' => function ($alias) {
         return sprintf("%s.programDate", $alias);
     }, 'value' => 'ASC'));
     return $this->entityManager->findBy(Listing::class, $criteria);
 }
开发者ID:erheme318,项目名称:simple-tv-listings,代码行数:16,代码来源:ChannelRepository.php


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