有没有快速的方法将日期转换为西班牙语?

时间:2016-07-23 16:42:50

标签: php

有了这个:

date( 'd F Y', strtotime( $row["datestart"] ) )

我明白了:

08 July 2016

但我需要得到这个:

08 Julio 2016

胡里奥7月份是西班牙语。

我已将此添加到php页面的顶部:

setlocale(LC_TIME, 'es_ES');

但它不起作用。

那我该怎么办?

3 个答案:

答案 0 :(得分:4)

这对我有用:

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是这里的关键因素。

答案 1 :(得分:1)

您可以使用的另一种变体:

intllink)安装php扩展名。 在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

答案 2 :(得分:0)

你可以创建一个关联数组。 将键设置为英语月份,将值设置为相应月份的西班牙语。

看起来像这样......

$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.

您可能也可以使用Google Translate的API,但对于可以通过简单数组完成的事情来说似乎太过分了。

如果您有兴趣翻译其他单词或更多单词,那么这里是Google Translate's API

相关问题