SimplePie 1.3.1 is now available. Upgrade now!

SimplePie Documentation.  Learn how to use this thing.  It's way better than going to school.

You are here: Documentation » Tips, Tricks, Tutorials, and Screencasts » Translate timestamps into another language

Translate timestamps into another language

By default, PHP displays timestamps in English. Since SimplePie's get_date() method relies on PHP's date() function, get_date() is English-only. However, in SimplePie 1.0 we introduced get_local_date() which leverages PHP's strftime() function which is designed to translate timestamps into other languages.

get_local_date() accepts values that are accepted by strftime(). We also need to call PHP's setlocale() function prior to using this method. setlocale() has it's own set of issues with region/language codes. It only supports whatever is installed in your PHP installation, and some servers require two or three-letter codes.

This will ONLY work for items that have timestamps.


  • Supported in SimplePie 1.0.
  • Code in this tutorial should be compatible with PHP 4.3 or newer, and should not use PHP short tags, in order to support the largest number of PHP installations.

Code source

// Set the region/language to Canadian French
setlocale(LC_TIME, 'fr_CA');
// As we loop through items, display the formatted, localized date.
foreach($feed->get_items() as $item) {
	echo '<p>' . $item->get_title() . ' ' . $item->get_local_date('%A %e %B %Y') . '</p>';

tutorial/translate_timestamps_into_another_language.txt · Last modified: 2011/03/05 19:56 (external edit)