CodeIgniter Forums
Format Date in a foreign language - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Format Date in a foreign language (/showthread.php?tid=85839)



Format Date in a foreign language - groovebird - 12-10-2022

Hi,

i need the weekday in german and want to use the CI4 Time library.

PHP Code:
use CodeIgniter\I18n\Time;

$time Time::parse('2022-12-10');
echo 
$time->format('D. d.m.Y'); 

This gives me the english weekday. Is this a setting from CI or a PHP setting? In CI4 i added "de" to defaultLocale and supportedLocales but it is not working.


RE: Format Date in a foreign language - Mni.day - 12-10-2022

PHP Code:
$time->toLocalizedString('D. d.m.Y'); 



RE: Format Date in a foreign language - groovebird - 12-10-2022

(12-10-2022, 03:58 PM)Mni.day Wrote:
PHP Code:
$time->toLocalizedString('D. d.m.Y'); 

This is not working, because the date format string is another one. but i will try it. Then i have to change alle date strings in my app.


RE: Format Date in a foreign language - InsiteFX - 12-11-2022

You can also useĀ IntlDateFormatter::format
PHP.NET - IntlDateFormatter::format


RE: Format Date in a foreign language - groovebird - 12-11-2022

(12-11-2022, 01:54 AM)InsiteFX Wrote: You can also useĀ IntlDateFormatter::format
PHP.NET - IntlDateFormatter::format

I think CI uses IntlDateFormatter under the hood if i use the "toLocalizedString" method.