format_date

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

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

Версии
5
format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL)
6
format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL)

Форматирует дату в заданном формате или в формате настроек сайта.

Друпал позволяет администратору определить для сайта несколько форматов дат — короткий ('small'), средний ('medium'), и длинный ('large'). Функция может принимать как эти значения, так и свободно заданный формат.

Параметры

$timestamp Дата в виде UNIX timestamp'а.

$type Формат даты. Может быть 'small', 'medium' или 'large' для предустановленных форматов. Если сюда передать "custom", то можно указать свой формат в параметре $format.

$format Строка с PHP-форматом даты, подходящим для функции date(). Не забывайте использовать обратный слеш, для экранирования служебных букв PHP-формата.

$timezone Смещение часового пояса в секундах; в случае отсутствия используется часовой пояс пользователя.

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

Переведенная строка с датой в нужном формате.

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

▾ 34 функции вызывают format_date()

blogapi_blogger_edit_post in modules/blogapi/blogapi.module
Коллбэк Blogging API. Модифицирует указанную ноду блога.
blogapi_blogger_new_post in modules/blogapi/blogapi.module
Коллбэк Blogging API. Вставляет новую запись блога как ноду.
chameleon_comment in themes/chameleon/chameleon.theme
chameleon_node in themes/chameleon/chameleon.theme
comment_admin_overview in modules/comment/comment.module
Конструктор формы; генерирует форму с кратким содержанием комментариев для администратора.
comment_form in modules/comment/comment.module
expand_date in includes/form.inc
Roll out a single date element.
filter_example_filter in developer/examples/filter_example.module
Реализация hook_filter().
format_date in includes/common.inc
Форматирует дату в заданном формате или в формате настроек сайта.
map_month in includes/form.inc
Вспомогательная функция используемая с drupal_map_assoc для показа названий месяцев.
node_form in modules/node/node.module
Generate the node add/edit form array.
node_object_prepare in modules/node/node.module
node_revisions in modules/node/node.module
Menu callback for revisions related activities.
node_revision_delete_confirm in modules/node/node.module
Ask confirmation for revision deletion to prevent against CSRF attacks.
node_revision_overview in modules/node/node.module
Generate an overview table of older revisions of a node.
node_revision_revert_confirm in modules/node/node.module
Ask for confirmation of the reversion to prevent against CSRF attacks.
node_revision_revert_confirm_submit in modules/node/node.module
phptemplate_comment in themes/engines/phptemplate/phptemplate.engine
Prepare the values passed to the theme_comment function to be passed into a pluggable template engine.
phptemplate_node in themes/engines/phptemplate/phptemplate.engine
Prepare the values passed to the theme_node function to be passed into a pluggable template engine.
statistics_access_log in modules/statistics/statistics.module
statistics_node_tracker in modules/statistics/statistics.module
statistics_recent_hits in modules/statistics/statistics.module
Menu callback; presents the 'recent hits' page.
statistics_user_tracker in modules/statistics/statistics.module
system_date_time_settings in modules/system/system.module
theme_aggregator_page_item in modules/aggregator/aggregator.module
Format an individual feed item for display on the aggregator page.
theme_comment in modules/comment/comment.module
theme_search_item in modules/search/search.module
Format a single result entry of a search query. This function is normally called by theme_search_page() or hook_search_page().
user_pass_reset in modules/user/user.module
Menu callback; process one time login link and redirects to the user page on success.
user_pass_submit in modules/user/user.module
user_register_submit in modules/user/user.module
watchdog_event in modules/watchdog/watchdog.module
Menu callback; displays details about a log message.
watchdog_overview in modules/watchdog/watchdog.module
Menu callback; displays a listing of log messages.
_blogapi_mt_extra in modules/blogapi/blogapi.module
Handles extra information sent by clients according to MovableType's spec.
_system_zonelist in modules/system/system.module

Код

<?php
function format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL) {
  if (!isset($timezone)) {
    global $user;
    if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
      $timezone = $user->timezone;
    }
    else {
      $timezone = variable_get('date_default_timezone', 0);
    }
  }

  $timestamp += $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 = '';
  for ($i = 0; $i < $max; $i++) {
    $c = $format[$i];
    if (strpos('AaDFlM', $c) !== FALSE) {
      $date .= t(gmdate($c, $timestamp));
    }
    else if (strpos('BdgGhHiIjLmnsStTUwWYyz', $c) !== FALSE) {
      $date .= gmdate($c, $timestamp);
    }
    else if ($c == 'r') {
      $date .= format_date($timestamp - $timezone, 'custom', 'D, d M Y H:i:s O', $timezone);
    }
    else if ($c == 'O') {
      $date .= sprintf('%s%02d%02d', ($timezone < 0 ? '-' : '+'), abs($timezone / 3600), abs($timezone % 3600) / 60);
    }
    else if ($c == 'Z') {
      $date .= $timezone;
    }
    else if ($c == '\\') {
      $date .= $format[++$i];
    }
    else {
      $date .= $c;
    }
  }

  return $date;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

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