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

kay899's avatar

Wrong date output on forge server

Hi,

I host my app via Forge on Digital Ocean.

Actually my only problem ist, that the date I have on my page is not show in German language. I use Carbon and do:

public function today()
{
    setlocale(LC_TIME, 'German');
    return Carbon::now('Europe/Berlin')->formatLocalized('%d. %B %Y');
}

What I ecpect to have is:

  1. Januar 2015

but I'll get:

  1. January 2015 (Month is in english)

On my local machine it is working.

Does someone has an idea what I need to do?

Thanks Andreas

0 likes
23 replies
bashy's avatar

Carbon docs say it works but...

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
RachidLaasri's avatar

PHP.net says : "The return value of setlocale() depends on the system that PHP is running. It returns exactly what the system setlocale function returns." so the server should be configured to work with all languages? or what?

Isn't it easy to use a package like the one mentioned above?

bashy's avatar

Yeah but when you set it with setlocale(LC_TIME, 'German') it will change it? Just like any other PHP setting.

kay899's avatar

But it seems Not to do the expected. How can I find out which Languages are installed with my PHP?

kay899's avatar

ok, German in definitely missing here:

How can I install that on the server? It's Digital Ocean and I use Forge.

Regards Andreas

bashy's avatar

You can check/install languages you want on your system with this

sudo dpkg-reconfigure locales
kay899's avatar

Thanks Bashy,

I now have de_DE.UTF-8 also in the list if I do "locale -a"

But my date format is not showing correctly. Here is my code:

 /**
 * Shows the actual date
 *
 * @return Response
 */
public function today()
{
    $dt = Carbon::now();
    setlocale(LC_TIME, 'German');
    return $dt->formatLocalized('%d. %B %Y');
}

Output on local maschine (XAMPP): 01. Februar 2015 [correct]

Output on server (Digital Ocean): 01. February 2015 [February should be Februar => German]

What is my problem here?

Thanks Andreas

bashy's avatar

Instead of returning the date, what about seeing what the locale is set to before and after you manually set the locale?

kay899's avatar

You mean this:

    $dt = Carbon::now();
    setlocale(LC_TIME, '');
    echo $dt->formatLocalized('%A %d %B %Y'); 
    setlocale(LC_TIME, 'German');
    echo $dt->formatLocalized('%A %d %B %Y'); 

On my local maschine it output for both: Sonntag 01 Februar 2015, which is German

Server for both: Sunday 01 February 2015, which is english

:-(

Any other idea?

bashy's avatar

Try this way then

setlocale(LC_TIME, 'de_DE');
bashy's avatar

Did you restart Apache/Nginx/PHP after installing new locales?

kay899's avatar

No, I haven't

How can I do that?

I use Forge as I am not really familiar with this server stuff. :-(

Is there also a way that Forge handles this? With recipes or something?

bashy's avatar

PHP FPM

sudo service php5-fpm restart

Nginx

sudo service nginx restart

// Or you can use this to spawn new workers without interrupting current connections
sudo nginx -s reload

Apache

sudo service apache2 restart
kay899's avatar

PHP FPM and Nginx restart has been successfully. Apache restart shows error: unrecongnized service

I also did a complete sudo reboot of the server, but still showing wrong date format. :-(

Would it be possible to have a skype or online session together and have a look on my system?

Thanks!

bashy's avatar
bashy
Best Answer
Level 65

Sorry I should of said that you do either Nginx OR Apache. Forge normally uses Nginx so Apache won't be found.

Here is a working example of it changing locale. I believe the missing .UTF-8 was the cause.

Commands used to install and check the DE locale

1 like
kay899's avatar

bashy, thanks so much for your help. You saved my day!

With .UTF-8 it is working now. :-)

Regards Andreas

Please or to participate in this conversation.