當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DateFormatterInterface::formatTimeDiffUntil方法代碼示例

本文整理匯總了PHP中Drupal\Core\Datetime\DateFormatterInterface::formatTimeDiffUntil方法的典型用法代碼示例。如果您正苦於以下問題:PHP DateFormatterInterface::formatTimeDiffUntil方法的具體用法?PHP DateFormatterInterface::formatTimeDiffUntil怎麽用?PHP DateFormatterInterface::formatTimeDiffUntil使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Core\Datetime\DateFormatterInterface的用法示例。


在下文中一共展示了DateFormatterInterface::formatTimeDiffUntil方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: formatTimestamp

 /**
  * Formats a timestamp.
  *
  * @param int $timestamp
  *   A UNIX timestamp to format.
  *
  * @return string
  *   The formatted timestamp string using the past or future format setting.
  */
 protected function formatTimestamp($timestamp)
 {
     $granularity = $this->getSetting('granularity');
     $options = ['granularity' => $granularity];
     if ($this->request->server->get('REQUEST_TIME') > $timestamp) {
         return SafeMarkup::format($this->getSetting('past_format'), ['@interval' => $this->dateFormatter->formatTimeDiffSince($timestamp, $options)]);
     } else {
         return SafeMarkup::format($this->getSetting('future_format'), ['@interval' => $this->dateFormatter->formatTimeDiffUntil($timestamp, $options)]);
     }
 }
開發者ID:ddrozdik,項目名稱:dmaps,代碼行數:19,代碼來源:TimestampAgoFormatter.php

示例2: formatTimestamp

 /**
  * Formats a timestamp.
  *
  * @param int $timestamp
  *   A UNIX timestamp to format.
  *
  * @return array
  *   The formatted timestamp string using the past or future format setting.
  */
 protected function formatTimestamp($timestamp)
 {
     $granularity = $this->getSetting('granularity');
     $options = ['granularity' => $granularity, 'return_as_object' => TRUE];
     if ($this->request->server->get('REQUEST_TIME') > $timestamp) {
         $result = $this->dateFormatter->formatTimeDiffSince($timestamp, $options);
         $build = ['#markup' => SafeMarkup::format($this->getSetting('past_format'), ['@interval' => $result->getString()])];
     } else {
         $result = $this->dateFormatter->formatTimeDiffUntil($timestamp, $options);
         $build = ['#markup' => SafeMarkup::format($this->getSetting('future_format'), ['@interval' => $result->getString()])];
     }
     CacheableMetadata::createFromObject($result)->applyTo($build);
     return $build;
 }
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:23,代碼來源:TimestampAgoFormatter.php

示例3: render

 /**
  * {@inheritdoc}
  */
 public function render(ResultRow $values)
 {
     $value = $this->getValue($values);
     $format = $this->options['date_format'];
     if (in_array($format, array('custom', 'raw time ago', 'time ago', 'raw time hence', 'time hence', 'raw time span', 'time span', 'raw time span', 'inverse time span', 'time span'))) {
         $custom_format = $this->options['custom_date_format'];
     }
     if ($value) {
         $timezone = !empty($this->options['timezone']) ? $this->options['timezone'] : NULL;
         $time_diff = REQUEST_TIME - $value;
         // will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence)
         switch ($format) {
             case 'raw time ago':
                 return $this->dateFormatter->formatTimeDiffSince($value, array('granularity' => is_numeric($custom_format) ? $custom_format : 2));
             case 'time ago':
                 return $this->t('%time ago', array('%time' => $this->dateFormatter->formatTimeDiffSince($value, array('granularity' => is_numeric($custom_format) ? $custom_format : 2))));
             case 'raw time hence':
                 return $this->dateFormatter->formatTimeDiffUntil($value, array('granularity' => is_numeric($custom_format) ? $custom_format : 2));
             case 'time hence':
                 return $this->t('%time hence', array('%time' => $this->dateFormatter->formatTimeDiffUntil($value, array('granularity' => is_numeric($custom_format) ? $custom_format : 2))));
             case 'raw time span':
                 return ($time_diff < 0 ? '-' : '') . $this->dateFormatter->formatTimeDiffSince($value, array('strict' => FALSE, 'granularity' => is_numeric($custom_format) ? $custom_format : 2));
             case 'inverse time span':
                 return ($time_diff > 0 ? '-' : '') . $this->dateFormatter->formatTimeDiffSince($value, array('strict' => FALSE, 'granularity' => is_numeric($custom_format) ? $custom_format : 2));
             case 'time span':
                 $time = $this->dateFormatter->formatTimeDiffSince($value, array('strict' => FALSE, 'granularity' => is_numeric($custom_format) ? $custom_format : 2));
                 return $time_diff < 0 ? $this->t('%time hence', array('%time' => $time)) : $this->t('%time ago', array('%time' => $time));
             case 'custom':
                 if ($custom_format == 'r') {
                     return format_date($value, $format, $custom_format, $timezone, 'en');
                 }
                 return format_date($value, $format, $custom_format, $timezone);
             default:
                 return format_date($value, $format, '', $timezone);
         }
     }
 }
開發者ID:papillon-cendre,項目名稱:d8,代碼行數:40,代碼來源:Date.php


注:本文中的Drupal\Core\Datetime\DateFormatterInterface::formatTimeDiffUntil方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。