May 29, 2011

PHP 時間計算

//時間差unit為60(分),3600(時)

function TimeCount($start, $end,$unit)

  $num = (strtotime($end)-strtotime($start))/$unit;
  return $num;
}

echo TimeCount('2011-02-01','2011-02-09',3600);

============================================
//計算使用期限, time使用使間,$unit變動單位,$changeunit輸出時變動單位

function TimeFuture($time, $unit, $changeUnit)
{
  $num = date($unit)+$time;
  switch($changeUnit){
     case 'Y':
        return date($num."-m-d");
     break;
     case 'm':       
        return date("Y-".$num."-d");
     break;   
     case 'd':
        return date ("Y-m-".$num);
     default:
        return 0;     
  }
  return date($output);
}

//現在時間三年後
echo TimeFuture(3, "Y","Y" );

Today's Visitors: 0 Total Visitors: 1
Personal Category: Uncategorized Articles Topic: learning / education / linguistic
[Trackback URL]

Post A Comment









Yes No



Please input the magic number:

( Prevent the annoy garbage messages )
( What if you cannot see the numbers? )
Please input the magic number

誰來收藏
Loading ...
unlog_NVPO 0