Jump to content

[Solved] datetime and multi-language support


Recommended Posts


On my project, I'm using the multi-language module to translate the site to 3 languages. Now I want to format the posts datetime on a custom way, and I found this method using date() to output weekday name, month name, and day number. But the output names are on English.

What is the best way to set the locale for each language added in the multi-language module?

$data = strtotime($publicacion->data_publicacion);
$contido .= '<em>' . date('l', $data) . '</em>' . "\n";
$contido .= '<strong>' . date('F', $data) . '</strong>' . "\n";
$contido .= '<span>' . date('d', $data) . '</span>' . "\n";
Edited by Laegnur
Link to comment
Share on other sites


@bernhard thanks for your answer. Now I understand how to set the locale for each language in the module and was able to achieve what I wanted.

Finally my date code would look like this

$data = strtotime($publicacion->data_publicacion);

$dateFormatter = \IntlDateFormatter::create(

$contido .= '<time datetime="' . $publicacion->data_publicacion . '">' ."\n";
$contido .= '<em>' . datefmt_format($dateFormatter, $data) . '</em>' . "\n";
$contido .= '<strong>' . datefmt_format($dateFormatter, $data) . '</strong>' . "\n";
$contido .= '<span>' . datefmt_format($dateFormatter, $data) . '</span>' . "\n";
$contido .= '</time>' . "\n";

And the final result:


  • Like 2
Link to comment
Share on other sites

  • Laegnur changed the title to [Solved] datetime and multi-language support

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...