简体   繁体   中英

Convert to capital letter the day and month names using PHP strftime()

When I want to show the time in the default timezone there is no problem, for example:

Friday, 12 de December del 2014

But the problem exist when I want to show it in other language (other timezone) for example Spanish , it outputs like this:

viernes, 12 de diciembre del 2014

The time format I am using is: "%A, %d de %B del %Y"

I would like to show like this: Viernes, 12 de Diciembre del 2014


I tried to solve it using the ucfirst() and ucwords() functions, but I think they aren't good solutions for this because it shows like this: Viernes, 12 De Diciembre Del 2014

Well, finally after searching a magic method that answer my question, I had no other alternative rather than using suggestion of user John Conde.

Here is the method I used:

$default_local_date = ucwords(utf8_encode(strftime("%A, %d de %B del %Y")));

$date_connectors_capital = array('De', 'Del');
$date_connectors_lower = array('de', 'del');

$local_date = str_replace($date_connectors_capital, $date_connectors_lower, $default_local_date);

echo $local_date;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM