function date_format_date in Date 5
Same name and namespace in other branches
- 5.2 date_api.module \date_format_date()
- 6.2 date_api.module \date_format_date()
- 6 date_api.module \date_format_date()
- 7.3 date_api/date_api.module \date_format_date()
- 7 date_api/date_api.module \date_format_date()
- 7.2 date_api/date_api.module \date_format_date()
Format date
Translate month and day text in date formats. Using gmdate so php won't try to adjust value for server timezone. Needed because date object has already made necessary timezone adjustments.
Similar to core format_date function but will work on old, pre-1970 dates if adodb library is available.
4 calls to date_format_date()
- date_formatter_setup_form in ./
date_admin.inc - A form to create a date formatter option
- date_ical_parse_duration in ./
date_api_ical.inc - Parse the duration of the event.
- date_show_date in ./
date.inc - A function to display formatted output for the date object
- _date_views_argument_range_handler in ./
date_views.inc
File
- ./
date.inc, line 456 - Date/time API functions
Code
function date_format_date($format, $timestamp, $offset = NULL, $timezone_name = NULL) {
$max = strlen($format);
if (isset($timezone_name) && !isset($offset)) {
$offset = date_offset(date_gmgetdate($timestamp), $timezone_name);
}
$date = '';
for ($i = 0; $i < $max; $i++) {
$c = $format[$i];
if (strpos('AaDFlM', $c) !== FALSE) {
$date .= t(date_gmdate($c, $timestamp));
}
elseif (strpos('BdgGhHiIjLmnsStUwWYyz', $c) !== FALSE) {
$date .= date_gmdate($c, $timestamp);
}
elseif ($c == 'r') {
$date .= date_format_date($timestamp, 'D, d M Y H:i:s O', $offset, $timezone_name);
}
elseif ($c == '\\') {
$date .= $format[++$i];
}
elseif ($c == 'O') {
if (isset($offset)) {
$hours = intval($offset / 3600);
$minutes = intval($offset / 60 - $hours * 60);
$date .= ' ' . sprintf('%+05d', $hours * 100);
}
}
elseif ($c == 'P') {
if (isset($offset)) {
$hours = intval($offset / 3600);
$minutes = intval($offset / 60 - $hours * 60);
$date .= ' ' . sprintf('%+03d', $hours) . ':' . sprintf('%02d', $minutes);
}
}
elseif ($c == 'e' || $c == 'T') {
if (isset($timezone_name)) {
$date .= ' ' . $timezone_name;
}
}
else {
$date .= $c;
}
}
return $date;
}