1

Well, the question is pretty obvious I guess.

If I have:

$now = new DateTime();
print $now->format('l, M d');

Can I output that date in a different language?

Peter
  • 8,776
  • 6
  • 62
  • 95
  • 1
    http://stackoverflow.com/questions/13845554/php-date-get-name-of-the-months-in-local-language – Salman A Jan 05 '15 at 13:16
  • It is not a `language` but a date time format. Change that and the question becomes much clearer – SuperDJ Jan 05 '15 at 13:17
  • @SalmanA That involves the date function. I would like to use DateTime – Peter Jan 05 '15 at 13:18
  • 3
    you can find the answer here: http://stackoverflow.com/questions/8744952/php-how-to-format-a-given-datetime-object-considering-localegetdefault – stefan Jan 05 '15 at 13:19

1 Answers1

7

PHP's intl extension has the IntlDateFormatter for this purpose.

$fmt = new IntlDateFormatter(
    'de-DE',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);

$date = new DateTime;
echo $fmt->format($date);
deceze
  • 510,633
  • 85
  • 743
  • 889
  • 1
    Also note that you're able to set a custom pattern via `$fmt->setPattern($thePattern)`. The patterns are described here: http://userguide.icu-project.org/formatparse/datetime – Sam Jul 17 '17 at 09:38