小兔网

本篇文章带大家介绍php计算当天剩余时间最便捷和最快的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

【推荐学习:PHP视频教程

最便捷的方法

echo strtotime('23:59:59')-time();

最快的方法

$now = time();echo 86400-date('H', $now)*3600- date('i', $now)*60-date('s');

更快的方法

echo 86400-(time()+8*3600)%86400;

附测试数据

xubanditdeMacBook-Pro:~ xubandit$ time php -f a.phpreal    0m31.146suser    0m30.966ssys    0m0.075sxubanditdeMacBook-Pro:~ xubandit$ time php -f b.phpreal    0m48.574suser    0m48.329ssys    0m0.098sxubanditdeMacBook-Pro:~ xubandit$ time php -f c.phpreal    0m11.156suser    0m10.786ssys    0m0.098sxubanditdeMacBook-Pro:~ xubandit$ cat a.php<?phpfor($i=0;$i<10000000;$i++){    strtotime('23:59:59')-time();}xubanditdeMacBook-Pro:~ xubandit$ cat b.php<?phpfor($i=0;$i<10000000;$i++){    $now = time();    86400-date('H', $now)*3600- date('i', $now)*60-date('s');}xubanditdeMacBook-Pro:~ xubandit$ cat c.php<?phpfor($i=0;$i<10000000;$i++){    86400-(time()+8*3600)%86400;}

以上就是分享php计算当天剩余时间最便捷和最快的方法的知识。速戳>>知识兔学习精品课!