2014-10-30, 06:42:52
PUBLISHED 19:25 / 13 poniedzia³ek, padziernik, 2014
strfttime does not support ordinal number suffixes, you would need to handle that on your own for your language.
1st, 2nd, 3rd
php 5.3 with PECL int supports i18n number formatting
This is all built into 3.4 already
PHP Code:
<p class="page-meta">Published <span><?php LOCAL_get_page_date('%H:%M / %e %A, %B, %Y'); ?></span></p>
<?php
setlocale(LC_ALL, 'pl-PL'); // you should probably have this in your gsconfig.php
// here are the 3.4 functions ported for local use
/**
* Get Page Date
*
* This will return the page's updated date/timestamp
*
* @since 1.0
* @uses $date
* @uses $TIMEZONE
*
* @param string $i Optional, default is "l, F jS, Y - g:i A"
* @param bool $echo Optional, default is true. False will 'return' value
* @return string Echos or returns based on param $echo
*/
function LOCAL_get_page_date($i = "l, F jS, Y - g:i A", $echo=true) {
global $TIMEZONE,$date;
if ($TIMEZONE != '') {
if (function_exists('date_default_timezone_set')) {
date_default_timezone_set($TIMEZONE);
}
}
$str = LOCAL_formatDate($i, strtotime($date));
if(!$echo) return $str;
echo $str;
}
/**
* Formated Date Output, special handling for params on windows
*
* @since 3.4
* @author cnb
*
* @param string $format A strftime or date format
* @param time $timestamp A timestamp
* @return string returns a formated date string
*/
function LOCAL_formatDate($format, $timestamp = null) {
if(!$timestamp) $timestamp = time();
if (strpos($format, '%') === false) {
$date = date($format, $timestamp);
}
else {
$hostIsWindows = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
if ($hostIsWindows) {
# fixes for Windows
$format = preg_replace('#(?<!%)((?:%%)*)%e#', '\1%#d', $format); // strftime %e parameter not supported
$date = utf8_encode(strftime($format, $timestamp)); // strftime returns ISO-8859-1 encoded string
} else {
$date = strftime($format, $timestamp);
}
}
return $date;
}
?>
strfttime does not support ordinal number suffixes, you would need to handle that on your own for your language.
1st, 2nd, 3rd
php 5.3 with PECL int supports i18n number formatting
PHP Code:
$nf = new NumberFormatter('en_US', NumberFormatter::ORDINAL);
print $nf->format(123); // prints 123rd
This is all built into 3.4 already