Environment:
CentOS 7.3.1611
PHP 7.1.3
Code:
echo setlocale(LC_ALL, array('zh_CN.UTF-8', 'zh_CN.utf8', 'zh_CN')), PHP_EOL;
$date = new DateTime();
echo $date->format('Y-F-d l'), PHP_EOL;
Output:
zh_CN.UTF-8
2017-May-22 Monday
Additional tests, in Shell:
# export LC_ALL=zh_CN.UTF_8
# date
2017年 05月 22日 星期一 19:02:15 CST
# export LC_ALL=en_US.UTF_8
# date
Mon May 22 19:02:34 CST 2017
Question:
It is possible to localize date output in Bash.
Why is it invalid to use the setlocale() function in PHP?
Please give me some advice.
Neither of the above two answers hit the point.
setlocale
setlocale
strftime
strftime
- Format local time/date according to localeThese two functions must be used together to see the effect.
However, even so, the performance is still different from when you directly call the system bash, and may not necessarily meet your expectations.
The date command in bash calls a date application in linux to realize the display and output of the date function
php is the date object and function implemented by itself
It’s quite understandable that the functions of the two are different!
These are two languages with different method mechanisms. If you are using
php
里面想得到中文这种格式,完全可以在php
中通过exec
调用shell
’s method: