我使用Codeigniter顯示日期。更改日期幫助程序語言Codeigniter
我有這個,但它的英語回聲,我如何將它設置爲其他語言?我已經有西班牙語語言包,但我無法弄清楚如何加載它。
$this->load->helper('date');
echo mdate("%F %d, %Y", strtotime(now()));
感謝
我使用Codeigniter顯示日期。更改日期幫助程序語言Codeigniter
我有這個,但它的英語回聲,我如何將它設置爲其他語言?我已經有西班牙語語言包,但我無法弄清楚如何加載它。
$this->load->helper('date');
echo mdate("%F %d, %Y", strtotime(now()));
感謝
// Set locale to Spanish Argentina, change to your installed language
setlocale(LC_TIME, 'es_AR');
echo strftime("%B %d, %Y", time());
首先,你不需要使用日期幫助實現這一目標。 mdate()
與strftime()
基本相同,只是變量略有不同。您的代碼strtotime(now())
也是錯誤的。 now()
與CI文檔中指出的time()
完全相同。它返回一個UNIX時間戳,strtotime()
將一個字符串轉換爲一個UNIX時間戳。所以你在做的是試圖將時間戳轉換爲時間戳,這當然是錯誤的。我更改了代碼,因此它不需要幫助程序,並且會以指定的語言正確輸出MONTHNAME DATE, YEAR
。請確保您將es_AR
更改爲您安裝的任何西班牙語言。這將是在格式es_COUNTRYCODE
¡太好了!謝謝! – 2013-03-20 16:55:18
在「calendar_lang.php」
$this->config->set_item('language', 'spanish');
$this->load->library('calendar');
echo 'Mes:'.$this->calendar->get_month_name(date('m'));
echo 'Día:'.$this->calendar->get_day_names(date('d'));
的TRADUCTIONS日期做了以下工作適合您嗎?順便說一句,如果你想將月份名稱大寫,只需將整個'strftime()'放在'ucfirst()'內。 – 2013-03-17 22:06:12