search
Homephp教程php手册一个求时间段的方法(MM-DD)格式


function m_d($v,$d) {
  $d = array(31,31,28,31,30,31,30,31,31,30,31,30,31);
  $t = split("\ ",$v);
  if($t[1] == $d[$t[0]] && $d>0) {
    $t[0]++;
    $t[1] = 1;
  }else if($t[1] == 1 && $d    $t[0]--;
    $t[1] = $d[$t[0]];
    if($t[0] == 0) $t[0] = 12;
  }else
    $t[1] .= $d;
  return sprintf("%02d %02d",$t[0],$t[1]);
}

function foo($ar) {
  static $p = 0;
  $retval = false;
  if($p == 0) {
    $p = $ar['end_dt'];
    return $retval;
  }
  if($p     $retval = array('start_dt' => m_d($p,1), 'end_dt' => m_d($ar['start_dt'],-1) );
  $p = $ar['end_dt'];
  return $retval; 
}
$a=array();
$a[0]['start_dt']="9 25";
$a[0]['end_dt']="10 05";
$a[1]['start_dt']="10 15";
$a[1]['end_dt']="10 30";
$a[2]['end_dt']="10 20";
$a[2]['end_dt']="11 20";
foreach($a as $v) {
  if($r = foo($v))
    $ar[] = $r;
}
print_r($ar);

?>



Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use