最新消息:

PHP函数第20款:两个时间相差的天数SubTime,不满1天按1天算

PHP扩展函数 杨红伟 4025浏览 0评论

一:函数简介

说实话,这个函数用的机会还真少,一般用不上。为什么这么说呢?首先说介绍一下这个函数,这个函数是一个时间减去另一个时间,时间的格式为time形式。返回的值为整型格式。也就是说时间差如果为0.1按1天计算,0.6也接1天计算。

这样我们用到它的机会就很少。

目前知道的,主要用在:

1、时间置顶,如果小于1或者几天就可以置顶;

2、其他方面,如果小于1按1天的这种方式来计算。

演示地址: http://www.ijquery.cn/phpfunction/SubTime/demo1.php

下载地址: http://www.ijquery.cn/phpfunction/SubTime/SubTime.zip

二:函数代码

/**
 *  两个时间相差的天数,不满1为1,注意ceil函数
 *
 * @param     int  $ntime  当前时间
 * @param     int  $ctime  减少的时间
 * @return    int
 */
if ( ! function_exists('SubTime'))
{
    function SubTime($ntime, $ctime)
    {
        $dayst = 3600 * 24;
        $cday = ceil(($ntime-$ctime)/$dayst);
        return $cday;
    }
}

Warning: Use of undefined constant PRC - assumed 'PRC' (this will throw an Error in a future version of PHP) in /www/wwwroot/www.ijquery.cn/wp-content/themes/d8-3.0/comments.php on line 17
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址