1

I tried to use setlocale() function on windows to convert days name in other language but it didn't work.

<?php setlocale(LC_ALL, 'nl_NL'); 
echo date("l", strtotime($variable); ?>

does anybody have an alternative for setlocale()? I use the Codeigniter framework.

rsp
  • 22,799
  • 6
  • 53
  • 66
Alexandru Florea
  • 536
  • 2
  • 7
  • 24
  • What's wrong with `setlocale`? – Aleks G Dec 21 '12 at 10:21
  • possible duplicate of [Unicode setlocale and strftime fails at windows](http://stackoverflow.com/questions/2197168/unicode-setlocale-and-strftime-fails-at-windows) - you didn't share which of the two causes were your actual problem: wrong locale name *or* using `date` *or* both. Please share what helped with your issue. – hakre Dec 21 '12 at 15:15

5 Answers5

5

You should consider using the extension intl which has IntlDateFormatter.

From the documentation:

$fmt = new IntlDateFormatter( "en_US" ,IntlDateFormatter::FULL,IntlDateFormatter::FULL,'America/Los_Angeles',IntlDateFormatter::GREGORIAN  );
echo "First Formatted output is ".$fmt->format(0);
$fmt = new IntlDateFormatter( "de-DE" ,IntlDateFormatter::FULL,IntlDateFormatter::FULL,'America/Los_Angeles',IntlDateFormatter::GREGORIAN  );
echo "Second Formatted output is ".$fmt->format(0);

which output

First Formatted output is Wednesday, December 31, 1969 4:00:00 PM PT
Second Formatted output is Mittwoch, 31. Dezember 1969 16:00 Uhr GMT-08:00
magnetik
  • 4,226
  • 38
  • 57
  • Pattern based formatting shown in a similar question: [Localized (short) month names using IntlDateFormatter in PHP?](http://stackoverflow.com/q/13992296/367456) – hakre Dec 21 '12 at 16:19
4

nl_NL is a typical Unix style locale name. On Windows, locales follow a different format. You want "nld", "holland", or "netherlands".

Additionally, date() is not locale-aware. You probably want strftime().

Álvaro González
  • 135,557
  • 38
  • 250
  • 339
2

date does not format dates according to locale. strftime does.

deceze
  • 491,798
  • 79
  • 706
  • 853
0
setlocale(LC_ALL, 'german');
echo (iconv('ISO-8859-2', 'UTF-8', strftime('%Y. %B %d. (%A)', mktime('0', '0', '0', '6', '18', '2010'))));

setlocale(LC_ALL, 'hungarian');
echo (iconv('ISO-8859-2', 'UTF-8', strftime('%Y. %B %d. (%A)', mktime('0', '0', '0', '6', '18', '2010'))));
rOcKiNg RhO
  • 631
  • 1
  • 6
  • 16
0

You can use strftime for local date:

setlocale(LC_TIME, 'it_IT');
$timestamp = strtotime("31-12-2012");
echo strftime("%A", $timestamp);
Davide
  • 1,523
  • 1
  • 14
  • 29