Search code examples
phptimesetlocale

Question and a problem about setlocale on windows according to information on php.net


Just a question about some information on setlocale i found on php.net http://php.net/manual/en/function.setlocale.php

It says:

Note:

On Windows, setlocale(LC_ALL, '') sets the locale names from the system's regional/language settings (accessible via Control Panel).

Does that mean if i add setlocale(LC_ALL, '') to my php, it should be the same local as my system? Because i have done that and it's still English with months.

When i echo out setlocale(LC_ALL, 0) i get this:

LC_COLLATE=C;LC_CTYPE=Norwegian (Bokm�l)_Norway.1252;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C

and when i echo out setlocale(LC_ALL, '') i get this:

Norwegian (Bokm�l)_Norway.1252

So i don't really know what to do from the echo it looks like its set to Norwegian and when i use setlocale(LC_ALL, '') i should also set everything to Norwegian including time, but it does not.

Here is also the code i use to change the time format.

date('d.F', strtotime($row['date2']))

Solution

  • SOLUTION: Use strftime() instead of strtotime().

    strtotime does not take into account the set locale.

    Before:

    date('d.F', strtotime($row['date2']))
    Output: 17.February
    

    After:

    setlocale(LC_ALL, '');
    strftime('%e.%B',strtotime($row['date2']))
    Output: 17.februar