PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, March 11, 2022

[FIXED] Why are my dates not properly localized with default_locale?

 March 11, 2022     cakephp, cakephp-4.x, locale     No comments   

Issue

I cannot figure out why my dates are not converted to FR locale, although I have properly setup the APP_DEFAULT_LOCALE in my app.php file.

I got Sun, 3 October, 09:00, but I would like to have Dim, 3 octobre, 09:00

Is there something else I need to do ?

'App' => [
        'namespace' => 'App',
        'encoding' => env('APP_ENCODING', 'UTF-8'),
        'defaultLocale' => env('APP_DEFAULT_LOCALE', 'fr_FR'),
        'defaultTimezone' => env('APP_DEFAULT_TIMEZONE', 'Europe/Brussels'),

Here is how I show the date in my view :

<?= h($upcomingEvent->startdate->format('D, j F, H:i')) ?>

Thanks for your help !


Solution

That setting does not affect the format() method, but the i18nFormat() method (and object to string conversion)!

Also be aware that the i18nFormat() method does not use the standard PHP formatting pattern syntax, but the ICU syntax:

$upcomingEvent->startdate->i18nFormat('E, d MMMM, HH:mm')

See also

  • Cookbook > Date & Time > i18nFormat()


Answered By - ndm
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing