PHP day of week numeric to day of week text not English

房东的猫 提交于 2019-12-06 14:08:12

问题


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.


回答1:


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().




回答2:


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



回答3:


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




回答4:


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'))));



回答5:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!