PHP中用于日期处理的常用函数有哪些?
- 内容介绍
- 文章标签
- 相关推荐
本文共计373个文字,预计阅读时间需要2分钟。
在开发过程中,我们常用日期和时间处理函数,以下是一些基本的例子:
php// 输出当前日期和时间,格式为年-月-日 时:分:秒echo date('Y-m-d H:i:s', time());
// 输出当前日期,格式为年-月-日echo date('Y-m-d', time());
开发过程中,常用日期处理函数,时间戳处理函数等,如下讲解: <?php echo date('Y-m-d h:i:s',time()); //运行结果(年月日时分秒,“-”间隔):2014-09-12 06:28:32 echo date('Y-m-d',time()); //运行结果(年月日,“-”间隔):2014-09-12 echo date('Y-m-d',strtotime(date('Y-m-d', time()-86400))); //运行结果(当前日期前一天的年月日,“-”间隔):2014-09-11 echo date('Ymd',time()); //运行结果(年月日,无间隔):20140912 echo date('m-d',time()); //运行结果(月日,“-”间隔):09-12 echo str_replace("-","月",date('m-d',time()-date('w',time())*86400))."日"; //运行结果(月日,汉字显示间隔):09月12日 echo date('w',time()); //运行结果(星期几):5 echo time(); //运行结果(当前日期时间的秒数):1410503809 echo strtotime(date('Y-m-d',time())); //运行结果(当前日期秒数,具体到天):1410503809 echo date('Y-m-d',strtotime(date('Y-m-d', time()))-date('w',strtotime(date('Y-m-d', time())))*86400); //运行结果(当前日期所属自然周的起始日期即周日的日期,具体到天,“-”间隔):2014-09-07
本文共计373个文字,预计阅读时间需要2分钟。
在开发过程中,我们常用日期和时间处理函数,以下是一些基本的例子:
php// 输出当前日期和时间,格式为年-月-日 时:分:秒echo date('Y-m-d H:i:s', time());
// 输出当前日期,格式为年-月-日echo date('Y-m-d', time());
开发过程中,常用日期处理函数,时间戳处理函数等,如下讲解: <?php echo date('Y-m-d h:i:s',time()); //运行结果(年月日时分秒,“-”间隔):2014-09-12 06:28:32 echo date('Y-m-d',time()); //运行结果(年月日,“-”间隔):2014-09-12 echo date('Y-m-d',strtotime(date('Y-m-d', time()-86400))); //运行结果(当前日期前一天的年月日,“-”间隔):2014-09-11 echo date('Ymd',time()); //运行结果(年月日,无间隔):20140912 echo date('m-d',time()); //运行结果(月日,“-”间隔):09-12 echo str_replace("-","月",date('m-d',time()-date('w',time())*86400))."日"; //运行结果(月日,汉字显示间隔):09月12日 echo date('w',time()); //运行结果(星期几):5 echo time(); //运行结果(当前日期时间的秒数):1410503809 echo strtotime(date('Y-m-d',time())); //运行结果(当前日期秒数,具体到天):1410503809 echo date('Y-m-d',strtotime(date('Y-m-d', time()))-date('w',strtotime(date('Y-m-d', time())))*86400); //运行结果(当前日期所属自然周的起始日期即周日的日期,具体到天,“-”间隔):2014-09-07

