Get day from string in spanish PHP

前端 未结 4 899
臣服心动
臣服心动 2020-12-31 07:45

I\'m trying with:

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


        
相关标签:
4条回答
  • 2020-12-31 08:06

    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"))];
    
    0 讨论(0)
  • 2020-12-31 08:13

    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 iconv to avoid strange symbols in accents, and i obtain this result:

    domingo, 09 de octubre de 2016
    
    0 讨论(0)
  • 2020-12-31 08:19

    From the DateTime format page:

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

    If you need locales look into strftime Example:

    setlocale(LC_ALL,"es_ES");
    $string = "24/11/2014";
    $date = DateTime::createFromFormat("d/m/Y", $string);
    echo strftime("%A",$date->getTimestamp());
    
    0 讨论(0)
  • 2020-12-31 08:22

    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";
    }  
    
    0 讨论(0)
提交回复
热议问题