php时间函数用法分析

2025-05-29 0 96

本文实例讲述了php时间函数用法。分享给大家供大家参考,具体如下:

php中有unix时间戳的 相关操作函数,使用很方便

time() 返回当前的 Unix 时间戳

microtime — 返回当前 Unix 时间戳和微秒数

例 1. 用 microtime() 对脚本的运行计时

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16
<?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 时间戳

?

1

2
echo strtotime("+1 day"), "/n";

echo strtotime("+1 week"), "/n";

例2. 某个时间的后一天,后一月

?

1

2

3
strtotime("+1 day ".$day);

strtotime("2008-01-31 +1 month");

strtotime($day." +1 day");

以上形式都正确

希望本文所述对大家PHP程序设计有所帮助。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 php时间函数用法分析 https://www.kuaiidc.com/97613.html

相关文章

发表评论
暂无评论