Outputting dates in non-ASCII characters with PHP

后端 未结 2 1844
南笙
南笙 2021-01-22 23:28

I\'m trying to output the date in Traditional Chinese.

I have the date as a Unix timestamp, ( example: \"1467244800\" ).

I am doing the following:



        
2条回答
  •  太阳男子
    2021-01-23 00:24

    Locales not only come in different languages, but also different encodings. The default zh_TW locale will probably use some Chinese encoding, while what you want is UTF-8. Hence, use the UTF-8 version of the locale:

    setlocale(LC_TIME, 'zh_TW.UTF-8');
    

    This depends on your specific system and what locales are installed on it. Check that on the command line:

    $ locale -a
    ...
    zh_TW
    zh_TW.Big5
    zh_TW.UTF-8
    

    To be more cross-platform compatible, you can try several locales:

    setlocale(LC_TIME, 'zh_TW.UTF-8', 'zh_TW.utf8', 'zh_TW');
    

提交回复
热议问题