【问题标题】:Change date helper language Codeigniter更改日期助手语言 Codeigniter
【发布时间】:2013-03-17 15:52:39
【问题描述】:

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

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

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

谢谢

【问题讨论】:

  • 以下内容对您有用吗?顺便说一句,如果您希望月份名称大写,只需将整个 strftime() 放在 ucfirst() 内。

标签: php codeigniter date helper


【解决方案1】:
// 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

【讨论】:

    【解决方案2】:

    “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'));
    

    【讨论】:

      猜你喜欢
      • 2017-05-02
      • 2015-11-12
      • 1970-01-01
      • 2023-04-08
      • 2012-08-11
      • 1970-01-01
      • 2012-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多