tags:

views:

1062

answers:

1

How to output a date in the locale date/time format in Joomla?

I'm creating a module which is supposed to print dates. I know I can dirty-hack it like that:

    strftime(format_string, strotime($date));

... but I would like a smoother solution, that would use Joomla's built-in locale handling functionality.

+1  A: 

In Joomla! 1.5 there is the JDate class:

function getLocalizedDate($date = 'now', $format_string = '%Y-%M-%D')
{
    jimport('joomla.utilities.date');
    $jdate = new JDate($date);
    return $jdate->toFormat(JText::_($format_string));
}

Weekday & Month names are localized by the JDate class, and additionally, if the format string is known (as '%Y-%M-%D'), it will be internationalized also - see the beginning of the file /language/xx_XX/xx_XX.ini (where xx is the used language.)

Note: JDate also applies the timezone set in configuration.php or overridden by the Joomla! user. Time fields should always be stored as +0000 GMT.

giraff