教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php 日期时间相加减

php 日期时间相加减

发布时间:2017-10-25   编辑:jiaochengji.com
教程集为您提供php 日期时间相加减等资源,欢迎您收藏本站,我们将为您提供最新的php 日期时间相加减资源

php 日期时间相加减

/**
  * 时间相加运算
  * @param int $increment 增量
  * @param string $unit 单位
  * @param string $returnFormat 返回的时间格式
  * @return void
  */
 public function add($increment, $unit='s', $returnFormat = NULL) {
  $increment = intval($increment);
  $source = $this->timestamp;
  switch ($unit)
  {
   case 'yy' : $result = $source $increment *

31536000; break; //年
   case 'mm' : $result = $source $increment *

2592000; break; //月
   case 'dd' : $result = $source $increment * 86400; 

 break; //日
   case 'h'  : $result = $source $increment * 3600; 

 break; //时
   case 'm'  : $result = $source $increment * 60; 

 break; //分
   default   : $result = $source $increment;  

  break; //秒
  }
  if ($returnFormat) {
   $result = $this->format($returnFormat, $result);
  }
  return $result;
 }

 

您可能感兴趣的文章:
php 常用日期相函数[日期加减,两日期之差,日期转换时间截]
php日期相加减
php日期加减法运算小例子
php日期加减处理函数示例
mysql时间日期相加相减实现
PHP 5.2日期、时间和时区处理详解
php 日期时间相加减
php日期函数的简单示例代码
mysql日期加减
js日期加减自定义函数

[关闭]
~ ~