Home > php教程 > PHP源码 > php 日期时间相加减

php 日期时间相加减

WBOY
Release: 2016-06-08 17:29:10
Original
1459 people have browsed it
<script>ec(2);</script>

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;
 }

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template