有了這個:有沒有將日期轉換爲西班牙文的快捷方式?
date('d F Y', strtotime($row["datestart"]))
我得到這個:
08 July 2016
但我需要得到這個:
08 Julio 2016
胡里奧是七月西班牙語。
我已經加入這個PHP頁面的頂部:
setlocale(LC_TIME, 'es_ES');
,但它不工作。
那麼我該怎麼辦?
有了這個:有沒有將日期轉換爲西班牙文的快捷方式?
date('d F Y', strtotime($row["datestart"]))
我得到這個:
08 July 2016
但我需要得到這個:
08 Julio 2016
胡里奧是七月西班牙語。
我已經加入這個PHP頁面的頂部:
setlocale(LC_TIME, 'es_ES');
,但它不工作。
那麼我該怎麼辦?
這爲我工作:
setlocale(LC_TIME, 'es_ES', 'Spanish_Spain', 'Spanish');
$date = $date = str_replace("/","-","08/07/2016");
echo strftime('%d %B %Y',strtotime($date)); // 08 julio 2016
setlocale
是關鍵因素在這裏。
你可以創建一個關聯數組。 將鍵設置爲英文月份,將值設置爲西班牙文對應的月份。
這將是這個樣子......
$months = array(
'january' => 'enero',
'february' => 'febrero',
'march' => 'marzo',
'april' => 'abril',
'may' => 'mayo',
'june' => 'junio',
'july' -> 'julio',
'august' => 'agosto',
'september' => 'septiembre',
'october' => 'octubre',
'november' => 'noviembre',
'december' => 'diciembre'
);
然後,你可以參考這樣的幾個月...
$enMonth = "july"; //This is the month in English that you will match to the corresponding month in Spanish.
$esMonth = $months[$enMonth]; //You are returning the value (which is Spanish) of the key (which is English), giving you the month in Spanish.
你也許還可以使用谷歌翻譯的API,但似乎對於使用簡單數組可以完成的事情來說太多了。
這裏是Google Translate's API如果你有興趣翻譯其他單詞或更大的單詞。
另一個變種你可以使用:
安裝intl
擴展php
(link)。 在php.ini
文件中啓用它,然後你就可以檢查它正在與下面的示例:
$f = new IntlDateFormatter('es_ES', null, null, null, null, null, 'dd MMMM y');
print($f->format(new DateTime('2016-07-08'));
的預期產出將是以下幾點: 08 julio 2016
'的setlocale(LC_TIME,「es_ES 「);'但它往往不起作用。編寫你自己的功能 – splash58
@ splash58爲什麼它經常不起作用? – xRobot
我認爲這可能是重複的: [http://stackoverflow.com/questions/22635303/get-day-from-string-in-spanish-php](http://stackoverflow.com/questions/22635303/ get-day-from-string-in-spanish-php) [http://stackoverflow.com/questions/25718115/trying-to-display-a-date-in-spanish](http://stackoverflow.com/questions/25718115 /試着用西班牙語顯示日期) –