Format date in PHP English and Spanish?

Asked

Viewed 422 times

2

I have that code PHP to format the date of a SQL:

setlocale(LC_ALL, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
date_default_timezone_set('America/Sao_Paulo');

I also need to do to English and Spaniard, how could I do?

  • 2

    Have you read the documentation of these two functions? What you understand and what you don’t understand?

  • 1

    You can create a function that asks the language as argument and returns the date in the desired format.

  • 1

    Available reading: http://www.learnaprogramar.com/index.php?option=com_content&view=arti&id=857:show-fecha-en-espanol-php-setlocale-strftime-formato-datedefault-Timezone-set-ejemplos-cu00831b&catid=70&Itemid=193

  • Soen - Spanish example: https://stackoverflow.com/questions/22635303/get-day-from-string-in-spanish-php

1 answer

4


Just follow the same line, placing the parameters according to the region, example:

Spaniard:

setlocale(LC_ALL, 'es_ES', 'es_ES.utf-8', 'es_ES.utf-8', 'esp');
date_default_timezone_set('America/Argentina/Mendoza');
echo strftime("%A %d de %B del %Y");

Brazil

setlocale(LC_ALL, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
date_default_timezone_set('America/Sao_Paulo');
echo strftime("%A %d de %B de %Y");

USA

setlocale(LC_ALL, 'us', 'us.utf-8', 'us.utf-8');
date_default_timezone_set('America/Los_Angeles');
echo strftime("%A %d de %B of %Y");

Some answers that may contribute additional information:

References:

  • I couldn’t get it to work in Spanish. códigosetlocale(LC_ALL, 'es_ES', 'es_ES.utf-8', 'es_ES.utf-8', 'esp'); date_default_timezone_set('America/Argentina/Mendoza'); echo strftime("%A %d of %B of %Y");

  • @Wagnermartinsbodyboard the 3 examples have been tested and are correct, which is that it did not work, as you are using?

  • 1

    I had to change my debian 8 configuration. Now it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.