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.
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()
.
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
date
does not format dates according to locale. strftime
does.
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'))));
You can use strftime
for local date:
setlocale(LC_TIME, 'it_IT');
$timestamp = strtotime("31-12-2012");
echo strftime("%A", $timestamp);
来源:https://stackoverflow.com/questions/13988225/php-day-of-week-numeric-to-day-of-week-text-not-english