php php根据时间增加

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php php根据时间增加相关的知识,希望对你有一定的参考价值。

<?php


/**
* Increase and decrease value based on date
*/
class woptimaDateIncrementalClass
{
	var $start;
	var $today;

	function __construct($startDate=null)
	{
		$this->start = new DateTime($startDate);
		$this->today = new DateTime();
	}

	private function get_difference($interval=null)
	{
		$difference = $this->start->diff($this->today);

		switch ($interval) {
			case 'y':
				return $difference->y;
				break;

			case 'm':
				return $difference->days/30;
				break;

			case 'w':
				return $difference->days/7;
				break;

			case 'd':
				return $difference->days;
				break;

			case 'h':
				return $difference->days*24;
				break;

			case 'm':
				return ($difference->days*24)*60;
				break;

			case 's':
				return (($difference->days*24)*60)*60;
				break;
			
			default:
				return $difference->days;
				break;
		}

	}

	function increase($interval, $qty=1, $amount=0, $base=0)
	{

		$diff = $this->get_difference($interval);

		$ret =  $base + ($amount * ($diff/$qty));

		return $ret;
	}

	function decrease($interval='d', $qty=1, $amount=0, $base=0)
	{
		$diff = $this->get_difference($interval);
		
		$ret =  $base - ($amount * ($diff/$qty));

		return round($ret);
	}

}

$woptimaDateIncremental = new woptimaDateIncrementalClass("22-12-1981");
echo $woptimaDateIncremental->increase('y', 1, 1, 300);

?>

以上是关于php php根据时间增加的主要内容,如果未能解决你的问题,请参考以下文章

PHP动态模式和静态模式区别

在ZendStudio中增加新的php模板

PHP的system解除了限制增加了权限为啥还是无法执行

周记 8

如何在php中增加最大执行时间[重复]

php-fpm优化方法详解