format_date

  1. drupal
    1. drupal6
    2. drupal7
Versionen
drupal6 – drupal7 format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL)

Format a date with the given configured format or a custom format string.

Drupal allows administrators to select formatting strings for 'small', 'medium' and 'large' date formats. This function can handle these formats, as well as any custom format.

Übergabeparameter

$timestamp The exact date to format, as a UNIX timestamp.

$type The format to use. Can be "small", "medium" or "large" for the preconfigured date formats. If "custom" is specified, then $format is required as well.

$format A PHP date format string as required by date(). A backslash should be used before a character to avoid interpreting the character as part of a date format.

$timezone Time zone identifier; if omitted, the user's time zone is used.

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

Rückgabewert

A translated date string in the requested format.

Verwandte Themen

▾ 42 functions call format_date()

blogapi_blogger_edit_post in modules/blogapi/blogapi.module
Blogging API callback. Modifies the specified blog node.
blogapi_blogger_new_post in modules/blogapi/blogapi.module
Blogging API callback. Inserts a new blog post as a node.
comment_admin_overview in modules/comment/comment.admin.inc
Form builder; Builds the comment overview form for the admin.
comment_form in modules/comment/comment.module
Generate the basic commenting form, for appending to a node or display on a separate page.
dblog_event in modules/dblog/dblog.admin.inc
Menu callback; displays details about a log message.
dblog_overview in modules/dblog/dblog.admin.inc
Menu callback; displays a listing of log messages.
drupalCreateNode in modules/simpletest/drupal_web_test_case.php
Creates a node based on default settings.
format_date in includes/common.inc
Format a date with the given configured format or a custom format string.
form_process_date in includes/form.inc
Roll out a single date element.
garland_node_submitted in themes/garland/template.php
Format the "Submitted by username on date/time" for each node.
hook_watchdog in modules/system/system.api.php
Log an event message
NodeRevisionsTestCase::testRevisions in modules/node/node.test
Check node revision related operations.
node_admin_nodes in modules/node/node.admin.inc
Form builder: Builds the node administration overview.
node_form in modules/node/node.pages.inc
Generate the node add/edit form array.
node_object_prepare in modules/node/node.pages.inc
node_revision_delete_confirm in modules/node/node.pages.inc
node_revision_delete_confirm_submit in modules/node/node.pages.inc
node_revision_overview in modules/node/node.pages.inc
Generate an overview table of older revisions of a node.
node_revision_revert_confirm in modules/node/node.pages.inc
Ask for confirmation of the reversion to prevent against CSRF attacks.
node_revision_revert_confirm_submit in modules/node/node.pages.inc
node_show in modules/node/node.module
Generate an array which displays a node detail page.
phptemplate_comment_submitted in themes/garland/template.php
Format the "Submitted by username on date/time" for each comment.
poll_votes in modules/poll/poll.pages.inc
Callback for the 'votes' tab for polls you can see other votes on
statistics_access_log in modules/statistics/statistics.admin.inc
Menu callback; Displays recent page accesses.
statistics_node_tracker in modules/statistics/statistics.pages.inc
statistics_recent_hits in modules/statistics/statistics.admin.inc
Menu callback; presents the "recent hits" page.
statistics_user_tracker in modules/statistics/statistics.pages.inc
system_date_time_lookup in modules/system/system.admin.inc
Return the date for a given format string via Ajax.
system_regional_settings in modules/system/system.admin.inc
Form builder; Configure the site date and time settings.
system_time_zones in modules/system/system.module
Generate an array of time zones and their local time&date.
template_preprocess_aggregator_item in modules/aggregator/aggregator.pages.inc
Process variables for aggregator-item.tpl.php.
template_preprocess_comment in modules/comment/comment.module
Process variables for comment.tpl.php.
template_preprocess_comment_folded in modules/comment/comment.module
Process variables for comment-folded.tpl.php.
template_preprocess_node in modules/node/node.module
Process variables for node.tpl.php
template_preprocess_search_result in modules/search/search.pages.inc
Process variables for search-result.tpl.php.
theme_comment_submitted in modules/comment/comment.module
Theme a "Submitted by ..." notice.
theme_node_submitted in modules/node/node.module
Format the "Submitted by username on date/time" for each node
theme_update_report in modules/update/update.report.inc
Theme project status report.
theme_update_version in modules/update/update.report.inc
Theme the version display of a project.
user_mail_tokens in modules/user/user.module
Return an array of token to value mappings for user e-mail messages.
user_pass_reset in modules/user/user.pages.inc
Menu callback; process one time login link and redirects to the user page on success.
_blogapi_mt_extra in modules/blogapi/blogapi.module
Handles extra information sent by clients according to MovableType's spec.

Code

includes/common.inc, line 1838

<?php
function format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) {
  static $timezones = array();
  if (!isset($timezone)) {
    global $user;
    if (variable_get('configurable_timezones', 1) && $user->uid && $user->timezone) {
      $timezone = $user->timezone;
    }
    else {
      $timezone = variable_get('date_default_timezone', 'UTC');
    }
  }
  // Store DateTimeZone objects in an array rather than repeatedly
  // contructing identical objects over the life of a request.
  if (!isset($timezones[$timezone])) {
    $timezones[$timezone] = timezone_open($timezone);
  }

  switch ($type) {
    case 'small':
      $format = variable_get('date_format_short', 'm/d/Y - H:i');
      break;
    case 'large':
      $format = variable_get('date_format_long', 'l, F j, Y - H:i');
      break;
    case 'custom':
      // No change to format.
      break;
    case 'medium':
    default:
      $format = variable_get('date_format_medium', 'D, m/d/Y - H:i');
  }

  $max = strlen($format);
  $date = '';
  // Create a DateTime object from the timestamp.
  $date_time = date_create('@' . $timestamp);
  // Set the time zone for the DateTime object.
  date_timezone_set($date_time, $timezones[$timezone]);

  for ($i = 0; $i < $max; $i++) {
    $c = $format[$i];
    if (strpos('AaeDlMT', $c) !== FALSE) {
      $date .= t(date_format($date_time, $c), array(), $langcode);
    }
    elseif ($c == 'F') {
      // Special treatment for long month names: May is both an abbreviation
      // and a full month name in English, but other languages have
      // different abbreviations.
      $date .= trim(t('!long-month-name ' . date_format($date_time, $c), array('!long-month-name' => ''), $langcode));
    }
    elseif (strpos('BcdGgHhIijLmNnOoPSstUuWwYyZz', $c) !== FALSE) {
      $date .= date_format($date_time, $c);
    }
    elseif ($c == 'r') {
      $date .= format_date($timestamp, 'custom', 'D, d M Y H:i:s O', $timezone, $langcode);
    }
    elseif ($c == '\\') {
      $date .= $format[++$i];
    }
    else {
      $date .= $c;
    }
  }

  return $date;
}
?>

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