format_interval

Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

includes/common.inc, строка 1146

Версии
5
format_interval($timestamp, $granularity = 2)
6
format_interval($timestamp, $granularity = 2, $langcode = NULL)

Форматирует временной интервал с заданной точностью.

Параметры

$timestamp Длина временного интервала в секундах.

$granularity Указывает, сколько различных временных единиц отображать в строке.

Возвращаемое значение

Переведенное строковое представление интервала.

Связанные темы

▾ 14 функции вызывают format_interval()

aggregator_view in modules/aggregator/aggregator.module
hook_requirements in developer/hooks/install.php
Check installation requirements that need to be satisfied.
statistics_top_pages in modules/statistics/statistics.module
Menu callback; presents the 'top pages' page.
statistics_top_referrers in modules/statistics/statistics.module
Menu callback; presents the 'referrer' page.
statistics_top_visitors in modules/statistics/statistics.module
Menu callback; presents the 'top visitors' page.
system_requirements in modules/system/system.install
Test and report Drupal installation requirements.
theme_aggregator_feed in modules/aggregator/aggregator.module
Format a news feed.
theme_aggregator_page_item in modules/aggregator/aggregator.module
Format an individual feed item for display on the aggregator page.
theme_aggregator_summary_item in modules/aggregator/aggregator.module
Return a themed item heading for summary pages located at 'aggregator/sources' and 'aggregator/categories'.
theme_comment_block in modules/comment/comment.module
Returns a formatted list of recent comments to be displayed in the comment block.
tracker_page in modules/tracker/tracker.module
Menu callback. Prints a listing of active nodes on the site.
user_admin_account in modules/user/user.module
user_user in modules/user/user.module
Реализация hook_user().
_forum_format in modules/forum/forum.module
Formats a topic for display

Код

<?php
function format_interval($timestamp, $granularity = 2) {
  $units = array('1 year|@count years' => 31536000, '1 week|@count weeks' => 604800, '1 day|@count days' => 86400, '1 hour|@count hours' => 3600, '1 min|@count min' => 60, '1 sec|@count sec' => 1);
  $output = '';
  foreach ($units as $key => $value) {
    $key = explode('|', $key);
    if ($timestamp >= $value) {
      $output .= ($output ? ' ' : '') . format_plural(floor($timestamp / $value), $key[0], $key[1]);
      $timestamp %= $value;
      $granularity--;
    }

    if ($granularity == 0) {
      break;
    }
  }
  return $output ? $output : t('0 sec');
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему