Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Alfabit's avatar

Get datetime format

Hy everyone, I have been looking for a few days now and I can not find anywhere some PHP function that would give me back datetime format for given locale. The problem is that a have a site intended for worldwide use so i want to display date and time in format that is used in selected country/locale. I would put as example smartphones. If you select English(US) language and input date will be formated as mm/dd/yyyy h:s AM/PM and if you select German iz will be dd.mm.yyyy H:i (I think thats te formats)

So does anyone know some way to get this format info or do I have to search for it on the web for all ~230 countries that i have?

Tnx :)

0 likes
6 replies
Cocoon's avatar

If you use Carbon (which is included in Laravel) you can format a date based on the country.

setlocale(LC_TIME, 'German');
echo $dt->formatLocalized('%A %d %B %Y'); // Donnerstag 25 Dezember 1975
setlocale(LC_TIME, '');
echo $dt->formatLocalized('%A %d %B %Y'); // Thursday 25 December 1975

https://github.com/briannesbitt/Carbon#api-formatting

1 like
Alfabit's avatar

Tnx guys, your answers were helpful but not really what I need. I have a config file in wich I set date format that is used over the web. So the thing I would really need some function that would return something like mm/dd/yyyy or dd.mm.yyyy

bashy's avatar

You can do that in Carbon (which is already linked in to Laravel), check the link again. There's so many date formats on there that you can use :)

Kenan-Amran's avatar

what is setlocal in arabic?? setlocale(LC_TIME, 'German');

Please or to participate in this conversation.