Home > php教程 > PHP源码 > body text

php日期转中文程序代码

WBOY
Release: 2016-06-08 17:21:58
Original
1021 people have browsed it

我们用到最多的日志肯定是数字型的日期了,但有时工作需要要把日期转换成中文要怎么处理?下面一起来看一个php日期转中文程序代码吧。

<script>ec(2);</script>

如果我们直接使用date函数获取日期显示的是数字的,如下

 代码如下 复制代码

   echo   date("Y-m-d");  
?>

输出的

2014-10-11

那么我们如果想得到

二零一四年十月十一日

怎么处理呢,后来看到一个朋友写了一句话函数

 代码如下 复制代码

#php日期转中文
$str = '2014-10-11';
echo str_replace(str_split('0123456789'), str_split('零一二三四五六七八九',3), date('Y',strtotime($str)).'年'.trim(str_replace('1十','十',implode('十', str_split(date('n',strtotime($str))))),'0').'月'.trim(str_replace('1十','十',implode('十', str_split(date('d',strtotime($str))))),'0')).'日';
?>

输出结果:

二零一四年十月十一日

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!