Forum Moderators: coopster

Message Too Old, No Replies

Current date in other language

...when setlocale() is not working

         

lukasz

9:57 am on Jan 19, 2004 (gmt 0)

10+ Year Member



I am trying to put current date on my page.
The format of the date should be (in Japanese)

2004, January 19, Monday

I tried something like:
<?
setlocale (LC_ALL, 'ja_JP.ujis');
$timestamp = time();

$date_time_array = getdate($timestamp);

$hours = $date_time_array["hours"];
$month = $date_time_array["mon"];
$day = $date_time_array["mday"];
$year = $date_time_array["year"];

$timestamp = mktime($hours + 13, $month, $day,$year);
echo strftime( " %Y.%B.%d,%A ",$timestamp);

?>
However it returns the date in japanese EUC encoding, and all my pages are in Shift_Jis encoding.

Any suggestions how I can display the date correctly?

g1smd

12:02 am on Jan 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



A compromise might be to use the RFC 3339 / ISO 8601 date format of YYYY-MM-DD which is all numeric like, for example, 2004-01-20.

Japanese people already know this standard as JIS-X-0301.

lukasz

3:24 am on Jan 20, 2004 (gmt 0)

10+ Year Member



I've done that - it was easy. However I need to do it in Japanese.
I thought about using if statement, for example
if month=1 then print January(in Japanese)
if day=2 then print Tuesday(in Japanese)
however I have no idea how to actually write it.
Would it work?

coopster

2:15 pm on Jan 20, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Sure, but an array would probably work better than the if statements:

$japanese_days = array(Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday);
$japanese_months = array(January, February, March, ...);
$day = $japanese_months[$date_time_array['wday']];
$month = $japanese_months[$date_time_array['mon']];

Of course, my Japanese is rusty (actually it's NULL), so you'll have to convert the English to Japanese in the arrays :)