天天看点

PHP中的日期和时间函数

<?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