English 中文(简体)
PHP 获得中间时间间隔
原标题:PHP obtain middle of time intervals
  • 时间:2012-05-24 19:43:45
  •  标签:
  • php
  • date
  • time

我开发了一个功能,以便在用户生成的时间框架内获得同等时间间隔。

$start         = strtotime("12:00");    //start at...
$end           = strtotime("18:00");    //end at...
$timeframe     = $end - $start;         //time-frame    
$intervals     = 3;                     //number of intervals within time-frame
$interval_time = $timeframe/$intervals; //time of each interval

for($i = 0, $start; 
    $i < $intervals; 
    $i++, $start = strtotime("+$interval_time seconds", $start)) //increment time
    { 
        $new_time = date( H:i:s a , $start); 
        echo "$new_time 
"; 
    }

以上输出的代码

 12:00:00 pm 14:00:00 pm 16:00:00 pm

我可以用什么代码来分隔每个间隔, 并获得中间线? 例如, 从上面的代码中获取

13:00:00 pm 15:00:00 pm 17:00:00 pm

(请说明:)

最佳回答

替换为 环 :

$half_interval = $interval_time / 2;
$mid = $start + $half_interval;
for ( $i = 1; $i < $intervals; $i ++) {
    echo date( H:i:s a , $mid) . " 
";
    $mid += $interval_time;
}
echo date( H:i:s a , $mid) . " 
";

我敢肯定,改进是可能的,但请留作读者的练习!-)

问题回答

暂无回答




相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签