Joomla! Localized Date Format

By Akbar

When working on a Joomla website, which is using the Urdu language package, I was trying to show the current date in Urdu on the top of the website header too. However, looks like finding the correct format string to convert the date to Urdu (or current language) was bit more tricky than I thought.I tried to find this in the Joomla support forums and documentation, but may be I was not using the correct search term, so didn’t found the relevant example.

After the search failure, I decided to explore the theme files to get idea on how this is done on the Article page, and I found the answer by looking at the article theme file at:
Joomlatemplates[Theme-Name]htmlcom_contentarticledefault.php

And for those of you, who don’t like to browse that file, and just want the solution, the following code worked for me:

1
2
3
<?php
	echo JHtml::_('date', JFactory::getDate(), JText::_('DATE_FORMAT_LC1'))
?>

The code itself is very simple. Basically, we are just getting the current date (second parameter), converting it to the correct date format, and then displaying it as HTML.

I hope this helps.

Tags: , , ,