0

我正在使用 Codeigniter 来显示日期。

我有这个但是它是用英语回显的,我如何将它设置为其他语言?我已经有了西班牙语语言包,但我不知道如何加载它。

 $this->load->helper('date');
 echo mdate("%F %d, %Y", strtotime(now()));

谢谢

4

2 回答 2

1
// Set locale to Spanish Argentina, change to your installed language
setlocale(LC_TIME, 'es_AR');

echo strftime("%B %d, %Y", time());

首先,您不需要使用日期助手来完成此操作。mdate()本质上与strftime()仅 vars 略有不同的地方相同。你的代码strtotime(now())也是错误的。与 CI 文档中指示now()的完全相同。time()它返回 UNIX 时间戳,strtotime()将字符串转换为 UNIX 时间戳。所以你所做的是试图将时间戳转换为时间戳,这当然是错误的。我更改了代码,因此它不需要帮助程序,并且会MONTHNAME DATE, YEAR以指定的语言正确输出。确保将其更改为es_AR您安装的任何西班牙语。它将是格式es_COUNTRYCODE

于 2013-03-17T17:19:57.520 回答
0

“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'));
于 2013-09-18T16:23:14.717 回答