Translate date("d F Y (H:i) function php

2019-03-15 14:37发布

I'm brazilian and there's a wordpress plugin that uses

" . date("d F Y (H:i)",$date) . "

Output: 16 January 2013 (00:54)

But it should be 16 Janeiro 2013 (00:54), in portuguese... How can I change it?

PS: I think maybe the date is set by an external file provided by the plugin creator :p I'm not sure though

3条回答
祖国的老花朵
2楼-- · 2019-03-15 14:39

The documentation for date already answers this:

To format dates in other languages, you should use the setlocale() and strftime() functions instead of date().

And strftime says that the way to do what is by using setlocale:

Format the time and/or date according to locale settings. Month and weekday names and other language-dependent strings respect the current locale set with setlocale().

That said, the C locale-aware functions do not provide sufficient functionality for languages that have cases. In such situations (i.e. most of the time) you need to roll your own.

查看更多
混吃等死
3楼-- · 2019-03-15 14:40

For the french language I use this

setlocale(LC_ALL, 'fra');

echo strftime("%A %d %B %Y",time()); 

For in portuguese

setlocale(LC_ALL, 'ptg');  //

echo strftime("%A %d %B %Y",time());

see Language Strings Country/Region Strings.

查看更多
Emotional °昔
4楼-- · 2019-03-15 14:46

WordPress has date_i18n to retrieve the date in localized format, based on timestamp.

Try:

echo date_i18n("d F Y (H:i)",$date) ;
查看更多
登录 后发表回答