码迷,mamicode.com
首页 > Web开发 > 详细

php时间函数的学习

时间:2015-09-02 23:19:53      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

手工画了一张图,来大体概括php中对于时间的处理函数

 

首先时间戳是这样“1441202665”的一串数字,虽然人看起来麻烦,但是计算机却很容易识别这样的时间表示形式。

所以给计算机看的时间是时间戳,给人看的是这样的“2015-09-02 22:25:30”字符串。

 

time()获取当前时间戳,返回类型是int

microtime()返回当前时间微妙数和时间戳组成的字符串,如果有true作为参数的话,返回微妙数作为小数部分的浮点数

mktime(hour,minute,second,month,day,year)将参数所代表的时间转换成时间戳,并返回。注意参数顺序

strtotime()将字符串转换成时间戳并返回,如

strtotime("now -1 day"); //昨天此时的时间戳

strtotime("now +1 day"); //明天此时的时间戳

除了day外,还可以使用week、month

strtotime("2015-09-02");//2015-09-02 00:00:00 的时间戳

strtotime("2015-09-02 22:39:30"); //返回2015-09-02 22:39:30的时间戳

再举其他几个例子:

strtotime("2015/09/02 22:39:30"); 

strtotime("20150902 22:39:30"); 

strtotime("20150902 223930"); 

strtotime("20150902223930");

以上形式返回结果是相同的

基本上只要你认真写正常的时间格式字符串,strtotime都能够转成时间戳的。 

 

php时间函数的学习

标签:

原文地址:http://www.cnblogs.com/lhat/p/4779587.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!