Skip to content

Instantly share code, notes, and snippets.

@smichaelsen
Created May 23, 2016 11:36
Show Gist options
  • Save smichaelsen/da082c84fb282e9db9daedea589968e8 to your computer and use it in GitHub Desktop.
Save smichaelsen/da082c84fb282e9db9daedea589968e8 to your computer and use it in GitHub Desktop.
PHP Date localization
<?php
setlocale(LC_TIME, 'de_DE');
echo (new DateTime())->format('F'); // May
echo strftime('%B', time()); // Mai
// BUT WHY!?
@Luzifer
Copy link

Luzifer commented May 23, 2016

I'd assume your LC_ALL or other locale is set to de_DE and strftime is using that locale while ->format isn't…

@thomashempel
Copy link

PHP Manual for DateTime->format says "This method does not use locales. All output is in English."

For strftime it says "Format the time and/or date according to locale settings. Month and weekday names and other language-dependent strings respect the current locale set with setlocale()."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment