Laegnur Posted September 26, 2022 Share Posted September 26, 2022 (edited) Hello 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 September 26, 2022 by Laegnur Solved Link to comment Share on other sites More sharing options...
bernhard Posted September 26, 2022 Share Posted September 26, 2022 1 Link to comment Share on other sites More sharing options...
Laegnur Posted September 26, 2022 Author Share Posted September 26, 2022 Hello @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( $languages->getLocale(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, \date_default_timezone_get(), \IntlDateFormatter::GREGORIAN ); $contido .= '<time datetime="' . $publicacion->data_publicacion . '">' ."\n"; $dateFormatter->setPattern('EEEE'); $contido .= '<em>' . datefmt_format($dateFormatter, $data) . '</em>' . "\n"; $dateFormatter->setPattern('MMMM'); $contido .= '<strong>' . datefmt_format($dateFormatter, $data) . '</strong>' . "\n"; $dateFormatter->setPattern('dd'); $contido .= '<span>' . datefmt_format($dateFormatter, $data) . '</span>' . "\n"; $contido .= '</time>' . "\n"; And the final result: 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now