19.5 Datum und Uhrzeiten lokalisieren

Problem

Sie wollen Datum und Uhrzeiten Locale-abhängig anzeigen.

Lösung

Verwenden Sie den Format-String %c von strftime( ):

print strftime('%c');

Sie können strftime( )-Format-Strings auch als Meldungen in Ihrem Meldungskatalog speichern:

$MC = new pc_MC_es_US;
print strftime($MC->msg('%Y-%m-%d'));

Diskussion

Der Format-String %c weist strftime( ) an, die gewünschte Datums- und Zeitangabe im Format des aktuellen Locale zurückzugeben. Die schnellste Art, einen nach dem Locale formatierten Zeit-String zu erzeugen, ist:

print strftime('%c');

Dieser Code produziert verschiedene Ergebnisse:

Tue Aug 13 18:37:11 2002 // in dem Default-Locale C mar 13 ago 2002 18:37:11 EDT // in dem Locale es_US mar 13 aoû 2002 18:37:11 EDT ...

Get PHP 5 Kochbuch now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.