php 从西班牙语PHP中的字符串中获取日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22635303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:09:47  来源:igfitidea点击:

Get day from string in spanish PHP

phpdatelocalization

提问by Mark

I'm trying with:

我正在尝试:

 setlocale(LC_ALL,"es_ES");
 $string = "24/11/2014";
 $date = DateTime::createFromFormat("d/m/Y", $string);
 echo $date->format("l");

And I'm getting Monday, which is correct but I need it in spanish, so, is there any way to retrieve this day in spanish?

我得到了星期一,这是正确的,但我需要西班牙语,所以,有什么方法可以用西班牙语检索这一天吗?

回答by Jim

From the DateTime format page:

从日期时间格式页面:

This method does not use locales. All output is in English.

此方法不使用语言环境。所有输出都是英文的。

If you need locales look into strftimeExample:

如果您需要语言环境,请查看strftime示例:

setlocale(LC_ALL,"es_ES");
$string = "24/11/2014";
$date = DateTime::createFromFormat("d/m/Y", $string);
echo strftime("%A",$date->getTimestamp());

回答by Javi Ps

I use:

我用:

setlocale(LC_ALL, "es_ES", 'Spanish_Spain', 'Spanish');
echo iconv('ISO-8859-2', 'UTF-8', strftime("%A, %d de %B de %Y", strtotime($row['date'])));

or

或者

setlocale(LC_ALL,"es_ES@euro","es_ES","esp");

both works. I have to use iconvto avoid strange symbols in accents, and i obtain this result:

两者都有效。我必须使用iconv来避免重音中的奇怪符号,我得到了这个结果:

domingo, 09 de octubre de 2016

回答by WhiteLine

use

set_locale(LC_ALL,"es_ES@euro","es_ES","esp");
echo strftime("%A %d de %B del %Y");

or

或者

function SpanishDate($FechaStamp)
{
   $ano = date('Y',$FechaStamp);
   $mes = date('n',$FechaStamp);
   $dia = date('d',$FechaStamp);
   $diasemana = date('w',$FechaStamp);
   $diassemanaN= array("Domingo","Lunes","Martes","Miércoles",
                  "Jueves","Viernes","Sábado");
   $mesesN=array(1=>"Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio",
             "Agosto","Septiembre","Octubre","Noviembre","Diciembre");
   return $diassemanaN[$diasemana].", $dia de ". $mesesN[$mes] ." de $ano";
}  

回答by Chris Denmark

This is how I did it.

我就是这样做的。

// Define key-value array
$days_dias = array(
'Monday'=>'Lunes',
'Tuesday'=>'Martes',
'Wednesday'=>'Miércoles',
'Thursday'=>'Jueves',
'Friday'=>'Viernes',
'Saturday'=>'Sábado',
'Sunday'=>'Domingo'
);

//lookup dia based on day name
$dia =  $days_dias[date('l', strtotime("1993-04-28"))];