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


PHP DateInterval::format方法代码示例

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


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

示例1: format

 /**
  * @param \DateInterval $interval
  * @return string
  */
 public static function format(\DateInterval $interval)
 {
     $string = $interval->format('%I:%S');
     if ($interval->h > 0) {
         $string = $interval->format('%H:') . $string;
     }
     if ($interval->d > 0) {
         $string = $interval->format('%D:') . $string;
     }
     return $string;
 }
开发者ID:stil,项目名称:phoebe,代码行数:15,代码来源:TimeDuration.php

示例2: run

 public function run()
 {
     // TODO initialize formatter settings at begin of request from user settings
     Yii::$app->formatter->timeZone = 'Europe/Berlin';
     $now = $this->getTimeComponent()->getStartTime();
     $end = clone $now;
     $end->add($this->duration);
     // TODO introduce constant for DateInterval format
     $strDuration = $this->duration->format('%H:%I:%S');
     $strEnd = Yii::$app->formatter->asDatetime($end);
     return "<div>Duration: {$strDuration}, until: {$strEnd}</div>";
 }
开发者ID:iw-reload,项目名称:iw,代码行数:12,代码来源:DurationWidget.php

示例3: format

 /**
  * Format a date (or interval) to a string with a given format
  *
  * See formatting options as in PHP date()
  *
  * @param integer|string|\DateTime|\DateInterval $date
  * @param string $format
  * @return string
  */
 public function format($date, $format)
 {
     if ($date instanceof \DateTimeInterface) {
         return $date->format($format);
     } elseif ($date instanceof \DateInterval) {
         return $date->format($format);
     } elseif ($date === 'now') {
         return date($format);
     } else {
         $timestamp = (int) $date;
         return date($format, $timestamp);
     }
 }
开发者ID:neos,项目名称:flow-development-collection,代码行数:22,代码来源:DateHelper.php

示例4: getDuration

 /**
  *
  * Return duration in seconds
  *
  * @return int, duration in seconds
  */
 public function getDuration()
 {
     $this->initialRequest();
     if (isset($this->item['contentDetails']['duration'])) {
         $date = new \DateInterval($this->item['contentDetails']['duration']);
         $ret = 0;
         $ret += (int) $date->format('%d') * 86400;
         $ret += (int) $date->format('%h') * 3600;
         $ret += (int) $date->format('%i') * 60;
         $ret += (int) $date->format('%s');
         return $ret;
     } else {
         $this->onApiBadInterpretation("contentDetails.duration not found");
     }
 }
开发者ID:lingtalfi,项目名称:YouTubeUtils,代码行数:21,代码来源:YouTubeVideo.php

示例5: formatWithoutZeroes

 public function formatWithoutZeroes()
 {
     // Each argument may have only one % parameter
     // Result does not handle %R or %r -- but you can retrieve that information using $this->format('%R') and using your own logic
     $parts = array();
     foreach (func_get_args() as $arg) {
         $pre = mb_substr($arg, 0, mb_strpos($arg, '%'));
         $param = mb_substr($arg, mb_strpos($arg, '%'), 2);
         $post = mb_substr($arg, mb_strpos($arg, $param) + mb_strlen($param));
         $num = intval(parent::format($param));
         $open = preg_quote($this->pluralCheck[0], '/');
         $close = preg_quote($this->pluralCheck[1], '/');
         $pattern = "/{$open}(.*){$close}/";
         list($pre, $post) = preg_replace($pattern, $num == 1 ? $this->singularReplacement : '$1', array($pre, $post));
         if ($num != 0) {
             $parts[] = $pre . $num . $post;
         }
     }
     $output = '';
     $l = count($parts);
     foreach ($parts as $i => $part) {
         $output .= $part . ($i < $l - 2 ? $this->separator : ($l == 2 ? $this->finalSeparator2 : ($i == $l - 2 ? $this->finalSeparator : '')));
     }
     return $output;
 }
开发者ID:filedit22,项目名称:J2JAY,代码行数:25,代码来源:time_difference.php

示例6: format

 public function format($format)
 {
     $callback = function ($value) {
         if ($value[0] === '%tm') {
             return $this->total_months;
         }
         if ($value[0] === '%tw') {
             return $this->total_weeks;
         }
         if ($value[0] === '%a' || $value[0] === '%td') {
             return $this->total_days;
         }
         if ($value[0] === '%th') {
             return $this->total_hours;
         }
         if ($value[0] === '%ti') {
             return $this->total_minutes;
         }
         if ($value[0] === '%ts') {
             return $this->total_seconds;
         }
         return parent::format($value[0]);
     };
     return preg_replace_callback('/%(?:[a-z]{1,2})+/i', $callback, $format);
 }
开发者ID:romeoz,项目名称:rock-date,代码行数:25,代码来源:DateInterval.php

示例7: testIsGreaterThanOrEqualTo

 public function testIsGreaterThanOrEqualTo()
 {
     $this->given($asserter = $this->newTestedInstance)->then->exception(function () use($asserter) {
         $asserter->isGreaterThanOrEqualTo(new \DateInterval('P1D'));
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Interval is undefined')->if($asserter->setWith(new \DateInterval('P1Y')))->then->object($asserter->isGreaterThanOrEqualTo(new \DateInterval('P1M')))->isIdenticalTo($asserter)->exception(function () use($asserter, &$interval) {
         $asserter->isGreaterThanOrEqualTo($interval = new \DateInterval('P2Y'));
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage('Interval ' . $asserter . ' is not greater than or equal to ' . $interval->format('%Y/%M/%D %H:%I:%S'));
 }
开发者ID:xihewang,项目名称:atoum,代码行数:8,代码来源:dateInterval.php

示例8: format

 /**
  * @param $format
  * @return mixed|string
  */
 public function format($format)
 {
     $formatted = parent::format($format);
     if ($this instanceof DateInterval && property_exists($this, 'u') && $this->u != 0) {
         $formatted = preg_replace('/([0-9]{1,2})S/', "\$1." . str_pad($this->u, 6, 0, STR_PAD_LEFT) . 'S', $formatted);
     }
     return $formatted;
 }
开发者ID:alexpts,项目名称:dtms,代码行数:12,代码来源:DateInterval.php

示例9: getListSongs

 public function getListSongs($search)
 {
     $youtubeResults = $this->getResponse($search, 'search');
     foreach ($youtubeResults['items'] as $subarray) {
         $youtubeResult = $this->getResponse($subarray['id']['videoId'], 'video');
         //pour obtenir la durée de la vidéo on exécute une requête sur les détails de la vidéo référencée par la videoId
         $duration = new \DateInterval($youtubeResult['items'][0]['contentDetails']['duration']);
         if ((int) $duration->format('%h') < 1 && (int) $duration->format('%d') < 1) {
             $duration = ((int) $duration->format('%h') * 3600 + (int) $duration->format('%i')) * 60 + (int) $duration->format('%s');
             //on récupère la durée en secondes
             $song = new Song();
             $song->setTitle($subarray['snippet']['title'])->setReference($subarray['id']['videoId'])->setProvider('youtube')->setAlbumCover($subarray['snippet']['thumbnails']['default']['url'])->setPreview('https://www.youtube.com/watch?v=' . $subarray['id']['videoId'])->setDuration($duration);
             $listSongs[] = $song;
             //return $listSongs;
         }
     }
     return $listSongs;
 }
开发者ID:gabrielvv,项目名称:superwknd,代码行数:18,代码来源:YoutubeAPI.php

示例10: buildPropertyBag

 /**
  * {@inheritdoc}
  */
 public function buildPropertyBag()
 {
     $this->properties = new PropertyBag();
     // mandatory information
     $this->properties->set('UID', $this->uniqueId);
     $this->properties->add($this->buildDateTimeProperty('DTSTAMP', $this->dtStamp ?: new \DateTime()));
     $this->properties->add($this->buildDateTimeProperty('DTSTART', $this->dtStart, $this->noTime));
     $this->properties->set('SEQUENCE', $this->sequence);
     $this->properties->set('TRANSP', $this->transparency);
     if ($this->status) {
         $this->properties->set('STATUS', $this->status);
     }
     // An event can have a 'dtend' or 'duration', but not both.
     if (null != $this->dtEnd) {
         $this->properties->add($this->buildDateTimeProperty('DTEND', $this->dtEnd, $this->noTime));
     } elseif (null != $this->duration) {
         $this->properties->set('DURATION', $this->duration->format('P%dDT%hH%iM%sS'));
     }
     // optional information
     if (null != $this->url) {
         $this->properties->set('URL', $this->url);
     }
     if (null != $this->location) {
         $this->properties->set('LOCATION', $this->location);
         if (null != $this->locationGeo) {
             $this->properties->add(new Property('X-APPLE-STRUCTURED-LOCATION', 'geo:' . $this->locationGeo, array('VALUE' => 'URI', 'X-ADDRESS' => $this->location, 'X-APPLE-RADIUS' => 49, 'X-TITLE' => $this->locationTitle)));
         }
     }
     if (null != $this->summary) {
         $this->properties->set('SUMMARY', $this->summary);
     }
     if (null != $this->attendee) {
         $this->properties->set('ATTENDEE', $this->attendee);
     }
     if (null != $this->description) {
         $this->properties->set('DESCRIPTION', $this->description);
     }
     if (null != $this->recurrenceRule) {
         $this->properties->set('RRULE', $this->recurrenceRule);
     }
     if ($this->cancelled) {
         $this->properties->set('STATUS', 'CANCELLED');
     }
     if (null != $this->organizer) {
         $this->properties->set('ORGANIZER', $this->organizer);
     }
     if ($this->noTime) {
         $this->properties->set('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE');
     }
     if ($this->created) {
         $this->properties->add($this->buildDateTimeProperty('CREATED', $this->created));
     }
     if ($this->modified) {
         $this->properties->add($this->buildDateTimeProperty('LAST-MODIFIED', $this->modified));
     }
 }
开发者ID:Langdi,项目名称:iCal,代码行数:59,代码来源:Event.php

示例11: setDuration

 /**
  * {@inheritdoc}
  */
 public function setDuration(\DateInterval $duration, $notify = TRUE)
 {
     // Generate an ISO 8601 formatted string as supported by
     // DateInterval::__construct() and setValue().
     $this->value = $duration->format('%rP%yY%mM%dDT%hH%mM%sS');
     // Notify the parent of any changes.
     if ($notify && isset($this->parent)) {
         $this->parent->onChange($this->name);
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:13,代码来源:DurationIso8601.php

示例12: transform

 /**
  * Transforms a DateInterval object into a date string with the configured format.
  *
  * @param \DateInterval $value A DateInterval object
  *
  * @return string An ISO 8601 or relative date string like date interval presentation
  *
  * @throws UnexpectedTypeException If the given value is not a \DateInterval instance.
  */
 public function transform($value)
 {
     if (null === $value) {
         return '';
     }
     if (!$value instanceof \DateInterval) {
         throw new UnexpectedTypeException($value, '\\DateInterval');
     }
     return $value->format($this->format);
 }
开发者ID:unexge,项目名称:symfony,代码行数:19,代码来源:DateIntervalToStringTransformer.php

示例13: getDefaultLength

 public function getDefaultLength()
 {
     $dateString = $this->webstream->getDbLength();
     $arr = explode(":", $dateString);
     if (count($arr) == 3) {
         list($hours, $min, $sec) = $arr;
         $di = new DateInterval("PT{$hours}H{$min}M{$sec}S");
         return $di->format("%Hh %Im");
     }
     return "";
 }
开发者ID:nidzix,项目名称:Airtime,代码行数:11,代码来源:Webstream.php

示例14:

 function format_interval(DateInterval $interval)
 {
     $result = "";
     if ($interval->y) {
         $result .= $interval->format("%y years ");
     }
     if ($interval->m) {
         $result .= $interval->format("%m months ");
     }
     if ($interval->d) {
         $result .= $interval->format("%d days ");
     }
     if ($interval->h) {
         $result .= $interval->format("%h hours ");
     }
     if ($interval->i) {
         $result .= $interval->format("%i minutes ");
     }
     return $result;
 }
开发者ID:esironal,项目名称:rssmonster,代码行数:20,代码来源:functions.php

示例15: _formatInterval

 private function _formatInterval(DateInterval $interval)
 {
     $result = "";
     if ($interval->y) {
         $result .= $interval->format("<span>%y</span>y ");
     }
     if ($interval->m) {
         $result .= $interval->format("<span>%m</span>m ");
     }
     if ($interval->d) {
         $result .= $interval->format("<span>%d</span>d ");
     }
     if ($interval->h) {
         $result .= $interval->format("<span>%h</span>h ");
     }
     if ($interval->i) {
         $result .= $interval->format("<span>%i</span>m ");
     }
     // if ($interval->s) { $result .= $interval->format("<span>%s</span>s "); }
     return $result;
 }
开发者ID:saqar,项目名称:FusionCMS-themes-and-modules,代码行数:21,代码来源:status.php


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