简体   繁体   English

PHP星期几数字到星期几文本(非英语)

[英]PHP day of week numeric to day of week text not English

I tried to use setlocale() function on windows to convert days name in other language but it didn't work. 我试图在Windows上使用setlocale()函数将日期名称转换为其他语言,但没有用。

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

does anybody have an alternative for setlocale() ? 有人可以替代setlocale()吗? I use the Codeigniter framework. 我使用Codeigniter框架。

You should consider using the extension intl which has IntlDateFormatter . 您应该考虑使用具有IntlDateFormatter的扩展名intl

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

nl_NL is a typical Unix style locale name. nl_NL是典型的Unix风格的语言环境名称。 On Windows, locales follow a different format . 在Windows上,语言环境采用不同的格式 You want "nld", "holland", or "netherlands" . 您需要“ nld”,“荷兰”或“荷兰”

Additionally, date() is not locale-aware. 此外, date()不支持区域设置。 You probably want strftime() . 您可能需要strftime()

date does not format dates according to locale. date不会根据语言环境设置日期格式。 strftime does. strftime可以。

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: 您可以将strftime用作本地日期:

setlocale(LC_TIME, 'it_IT');
$timestamp = strtotime("31-12-2012");
echo strftime("%A", $timestamp);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM