Found a little workaround, since the mysql2date() function doesn’t seem to work. Here is my solution of displaying the date localized in modules like SimpleLife, Profilactic or ComplexLife (these modules are basically the same):
$str = $item->get_date(get_option('simple_date'));
if (($timestamp = strtotime($str)) === false) {
echo "ERROR: The string ($str) is bogus";
} else {
echo '<li class="date">' . strftime("%A, %e %B", $timestamp) . '</li>' . "\r\n";
}
A additional tweak to show special characters within the date string I had to use the htmlentities() function.
// Since they're different, let's replace the old stored date with the new one
$stored_date = $item_date;
// Display it on the page
$str = $item->get_date(get_option('simple_date'));
if (($timestamp = strtotime($str)) === false) {
echo "ERROR: The string ($str) is bogus";
} else {
echo '<li class="date">' . htmlentities(strftime("%A, %e %B", $timestamp)) . '</li>' . "\r\n";
}
You have to convert the date to the format 'Y-m-d H:i:s' before you can use mysql2date().
For example:
$localized_date = mysql2date($date_format, date('Y-m-d H:i:s',get_option('simple_date'));
This single string does this:
- Converts
get_option('simple_date') to the format 'Y-m-d H:i:s'; 1221064200 becomes 2008-9-10 11:30:00
- mysql2date() translates the string into the current localization using the
$date_format variable; 2008-9-10 11:30:00 becomes 10. септембар 2008. 23:30 if the locale is Serbian and the $date_format = 'j. F Y. G:i';
If the blog date is September 10, 2008 10:41 PM in English, $localized_date will return as 10. септембар 2008. 22:41 in Serbian if I set the $date_format variable as j. F Y. G:i.
I hope this helps.