本文实例讲述了php时间函数用法。分享给大家供大家参考,具体如下:
php中有unix时间戳的 相关操作函数,使用很方便
time() 返回当前的 Unix 时间戳
microtime -- 返回当前 Unix 时间戳和微秒数
例 1. 用 microtime() 对脚本的运行计时
<?php
/**
* Simple function to replicate PHP 5 behaviour
*/
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float();
// Sleep for a while
usleep(100);
$time_end = microtime_float();
$time = $time_end - $time_start;
echo "Did nothing in $time seconds/n";
?>
mktime()取得一个日期的 Unix 时间戳
int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )
参数可以从右向左省略,任何省略的参数会被设置成本地日期和时间的当前值
date()格式化一个本地时间/日期
string date ( string format [, int timestamp] )
提示: 自 PHP 5.1 起在 $_SERVER['REQUEST_TIME'] 中保存了发起该请求时刻的时间戳。
strtotime -- 将任何英文文本的日期时间描述解析为 Unix 时间戳
echo strtotime("+1 day"), "/n";
echo strtotime("+1 week"), "/n";
例2. 某个时间的后一天,后一月
strtotime("+1 day ".$day);
strtotime("2008-01-31 +1 month");
strtotime($day." +1 day");
以上形式都正确
PS:本站还提供了一个Unix时间戳转换工具,非常实用,提供给大家参考:
Unix时间戳(timestamp)转换工具:
http://tools.haodaima.com/code/unixtime
这里再为大家推荐一款本站的php格式化美化的排版工具,帮助大家在以后的PHP程序设计中进行代码排版:
php代码在线格式化美化工具:
http://tools.haodaima.com/code/phpformat
另外,由于php属于C语言风格,因此下面这款工具同样可以实现php代码的格式化:
C语言风格/HTML/CSS/json代码格式化美化工具:
http://tools.haodaima.com/code/ccode_html_css_json
希望本文所述对大家PHP程序设计有所帮助。
到此这篇关于php时间函数用法分析就介绍到这了。生命本是一泓清泉,只有挑战自我的人才能品味出其中的甘洌;生命本是一部史书,只有挑战自我的人才能体味出其中的浩荡;生命就像一首优美的歌曲,只有挑战自我的人才能谱写出优美的旋律。更多相关php时间函数用法分析内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!