簡體   English   中英

PHP星期幾數字到星期幾文本(非英語)

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

我試圖在Windows上使用setlocale()函數將日期名稱轉換為其他語言,但沒有用。

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

有人可以替代setlocale()嗎? 我使用Codeigniter框架。

您應該考慮使用具有IntlDateFormatter的擴展名intl

文檔中

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

哪個輸出

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是典型的Unix風格的語言環境名稱。 在Windows上,語言環境采用不同的格式 您需要“ nld”,“荷蘭”或“荷蘭”

此外, date()不支持區域設置。 您可能需要strftime()

date不會根據語言環境設置日期格式。 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'))));

您可以將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