Forum Moderators: coopster

Message Too Old, No Replies

strftime to Locale's Long Date

         

Jeremy_H

4:17 pm on Nov 29, 2006 (gmt 0)

10+ Year Member



Hello,

I have different dates stored as seconds from the Unix Epoch.

On different pages, I'm trying to write these dates according to the page's specified local.

As an example, some outputs would look like this:

Chinese (PRC): 2006”N11ŒŽ29“ú
Spanish (Spain): 29 de noviembre de 2006
German (Germany): 29. November 2006

I know I want to use PHP's strftime to write these dates, but I'm not exactly clear what I should write.

echo strftime("________",$calendar[key($event)]["date"]);

I would imagine for Chinese I could write "%Y”N%bŒŽ%e“ú",
I would also imagine German I could write "%e. %B %Y".

The Spanish concerns me because it includes things like "de" which (possibly) might change depending on the date. Is it like English's 1st, 2nd, 3rd, 4th?

This makes me wonder if there is just a nice simple way to output the long date to the current local, short of having to construct from smaller pieces?

Thanks

(Please note that the Chinese characters are not showing based on the chartype of this forum).

[edited by: Jeremy_H at 4:19 pm (utc) on Nov. 29, 2006]

coopster

4:58 pm on Nov 29, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You will likely either have to create your own process to handle each language possibility or find a class that somebody else has already written and employ that instead. The only "built-in" option I am aware of is the "
%c - preferred date and time representation for the current locale
" option of the strftime() [php.net] function. But likely not the "long date" format you desire. Also, you will find that different platforms (*nix versus Windows) will return different results for the exact same locale because of the way each Operating System (OS) handles locales. For example, a Spanish locale request on two different servers requesting the current date in
%c
format:
// Unix PHP 5.1.4: 
mié 29 nov 2006 11:50:13 EST
// Windows PHP 5.1.4
29/11/2006 10:53:13