format_interval

  1. drupal
    1. drupal6
    2. drupal7
Versionen
drupal6 – drupal7 format_interval($timestamp, $granularity = 2, $langcode = NULL)

Format a time interval with the requested granularity.

Übergabeparameter

$timestamp The length of the interval in seconds.

$granularity How many different units to display in the string.

$langcode Optional language code to translate to a language other than what is used to display the page.

Rückgabewert

A translated string representation of the interval.

Verwandte Themen

▾ 17 functions call format_interval()

aggregator_view in modules/aggregator/aggregator.admin.inc
Displays the aggregator administration page.
hook_requirements in modules/system/system.api.php
Check installation requirements and do status reporting.
statistics_top_pages in modules/statistics/statistics.admin.inc
Menu callback; presents the "top pages" page.
statistics_top_referrers in modules/statistics/statistics.admin.inc
Menu callback; presents the "referrer" page.
statistics_top_visitors in modules/statistics/statistics.admin.inc
Menu callback; presents the "top visitors" page.
system_requirements in modules/system/system.install
Test and report Drupal installation requirements.
template_preprocess_aggregator_feed_source in modules/aggregator/aggregator.pages.inc
Process variables for aggregator-feed-source.tpl.php.
template_preprocess_aggregator_item in modules/aggregator/aggregator.pages.inc
Process variables for aggregator-item.tpl.php.
template_preprocess_aggregator_summary_item in modules/aggregator/aggregator.pages.inc
Process variables for aggregator-summary-item.tpl.php.
template_preprocess_forum_submitted in modules/forum/forum.module
Process variables to format submission info for display in the forum list and topic list.
theme_comment_block in modules/comment/comment.module
Returns a formatted list of recent comments to be displayed in the comment block.
theme_update_report in modules/update/update.report.inc
Theme project status report.
tracker_page in modules/tracker/tracker.pages.inc
Menu callback. Prints a listing of active nodes on the site.
user_admin_account in modules/user/user.admin.inc
Form builder; User administration page.
user_user_view in modules/user/user.module
Implementation of hook_user_view().
_batch_finished in includes/batch.inc
End the batch processing.
_batch_process in includes/batch.inc
Process sets in a batch.

Code

includes/common.inc, line 1788

<?php
function format_interval($timestamp, $granularity = 2, $langcode = NULL) {
  $units = array(
    '1 year|@count years' => 31536000,
    '1 month|@count months' => 2592000,
    '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], array(), $langcode);
      $timestamp %= $value;
      $granularity--;
    }

    if ($granularity == 0) {
      break;
    }
  }
  return $output ? $output : t('0 sec', array(), $langcode);
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen