Moshe Marciano
Moshe Marciano

Reputation: 2337

PHP: strftime ignoring setlocale when time is formatted

I am trying to output a date time value in the current locale, but while playing around with it and trying the en_US locale for example, it seems to still be using the 24 hours time format and not 5:13:17 PM.

for example this code:

setlocale(LC_TIME, 'en_US');
echo strftime("%c");
echo strftime("%x %X %p");

outputs:

Wed Nov 12 17:23:17 2014
11/12/14 17:23:17 PM

I thought it may be a ubuntu server config issue, but locale -a returns(amongst others):

en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US
en_US.iso88591
en_US.utf8

any ideas?

thanks


UPDATE

from the command line on my ubuntu 12.04LTS server:

>date --date='2014-11-13 16:21:42' +%X

04:21:42 PM

>locale

LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

>sudo dpkg-reconfigure locales

Generating locales...
  de_AT.UTF-8... up-to-date
  de_BE.UTF-8... up-to-date
  de_CH.UTF-8... up-to-date
  de_DE.UTF-8... up-to-date
  de_LI.UTF-8... up-to-date
  de_LU.UTF-8... up-to-date
  en_AG.UTF-8... up-to-date
  en_AU.UTF-8... up-to-date
  en_BW.UTF-8... up-to-date
  en_CA.UTF-8... up-to-date
  en_DK.UTF-8... up-to-date
  en_GB.UTF-8... up-to-date
  en_HK.UTF-8... up-to-date
  en_IE.UTF-8... up-to-date
  en_IN.UTF-8... up-to-date
  en_NG.UTF-8... up-to-date
  en_NZ.UTF-8... up-to-date
  en_PH.UTF-8... up-to-date
  en_SG.UTF-8... up-to-date
  en_US.ISO-8859-1... up-to-date
  en_US.UTF-8... up-to-date
  en_ZA.UTF-8... up-to-date
  en_ZM.UTF-8... up-to-date
  en_ZW.UTF-8... up-to-date
Generation complete.

Upvotes: 2

Views: 2032

Answers (1)

Moshe Marciano
Moshe Marciano

Reputation: 2337

guys turns out all I had to do was to restart apache(!), for some reason it needed reload locale..

I also needed to append .UTF8 to my calls, like this

setlocale(LC_TIME, 'en_US.UTF8');

thank you everyone and I hope this helps others in the future

Upvotes: 3

Related Questions