PHP中的日期和时间函数

来源:互联网 发布:软件架构 书籍 编辑:程序博客网 时间:2024/05/29 15:07

开发过程中,常用日期处理函数,时间戳处理函数等,如下讲解:

<?phpecho date('Y-m-d h:i:s',time());//运行结果(年月日时分秒,“-”间隔):2014-09-12 06:28:32echo date('Y-m-d',time());//运行结果(年月日,“-”间隔):2014-09-12echo date('Y-m-d',strtotime(date('Y-m-d', time()-86400)));//运行结果(当前日期前一天的年月日,“-”间隔):2014-09-11echo date('Ymd',time());//运行结果(年月日,无间隔):20140912echo date('m-d',time());//运行结果(月日,“-”间隔):09-12echo str_replace("-","月",date('m-d',time()-date('w',time())*86400))."日";//运行结果(月日,汉字显示间隔):09月12日echo date('w',time());//运行结果(星期几):5echo time();//运行结果(当前日期时间的秒数):1410503809echo strtotime(date('Y-m-d',time()));//运行结果(当前日期秒数,具体到天):1410503809echo date('Y-m-d',strtotime(date('Y-m-d', time()))-date('w',strtotime(date('Y-m-d', time())))*86400);//运行结果(当前日期所属自然周的起始日期即周日的日期,具体到天,“-”间隔):2014-09-07

原文链接https://www.oschina.net/code/snippet_2009720_38789

原创粉丝点击