【问题标题】:PHP What is the date and time every X minutes for the next Y minutes?PHP 接下来 Y 分钟每 X 分钟的日期和时间是多少?
【发布时间】:2020-03-23 03:21:21
【问题描述】:

Windows 10 64 位。 PHP 7.4.1

您最喜欢的网页是否返回带有围绕时间戳构建的 URL 的数据?这个问题试图用 PHP date() 复制这些 URL。

对我来说,最困难的部分是起点:

从分钟开始向下舍入到最接近的 10(19 变为 10)年、月、日、小时、分钟和秒总是 00 每 10 分钟持续 120 分钟?时间戳有两种格式:

032320200030 and 202003230030

mdYHi and YmdHi

我喜欢strtotime

date('mdYHi', strtotime("+10 minutes"));
date('YmdHi', strtotime("+10 minutes"));

但我无法将起点融入其中。

(floor(date("i") / 10) * 10)

从分钟开始向下舍入到最接近的 10(19 变为 10)。

【问题讨论】:

    标签: php windows-10


    【解决方案1】:

    Windows 10 64 位。 PHP 7.4.1

    PHP 从 floor(date(“i”) / 10) * 10 开始 date(“Y”), date(“m”), date(“d”), date(“H”) , date(“i”) 每 10 分钟一次,持续 120 分钟在服务器返回数据:

    <?php 
    ECHO  "<br />This is ".$_SERVER['SCRIPT_FILENAME']."<br />"; echo "Timestamp ".date("H:i:s mdy")."<br />";
    // $executionStartTime = microtime(true); //measure performance 
    // restore leading zero if minutes < than 10.
    if (date("i") < "10"){$zfloordate="0".(floor(date("i") / 10) * 10);}else{$zfloordate=(floor(date("i") / 10) * 10);} 
    // ob_start(); //output to file to measure performance
    echo "the minute is :".date("i")."<br />"; 
    echo "the floor minute is: $zfloordate<br />";
    // adjust timezone: The server creating the timestamps is in a different timezone (+3). Flooring minute < 10 returns 0. Restore leading zero w/ str_pad. Second is always 00.
    $selectedTime = date("YmdH", strtotime("+3 hours")).str_pad((floor(date("i") / 10) * 10), 2, '0', STR_PAD_LEFT).'00';
    $z = DateTime::createFromFormat('YmdHis', $selectedTime);
    $zY["00"] = $z->format('YmdHis'); 
    for($i = 10; $i <= 110; $i+=10) { 
    $z->modify('+10 minutes'); 
    $zY["$i"] = $z->format('YmdHis'); 
    }
    $selectedTime = date("mdYH", strtotime("+3 hours")).str_pad((floor(date("i") / 10) * 10), 2, '0', STR_PAD_LEFT).'00';
    $z = DateTime::createFromFormat('mdYHis', $selectedTime);
    $zM["00"] = $z->format('mdYHis'); 
    for($i = 10; $i <= 110; $i+=10) { 
    $z->modify('+10 minutes'); 
    $zM["$i"] = $z->format('mdYHis'); 
    } 
    echo "<br />";
    foreach ($zY as $key => $value){echo "The value at \$zY$key is $value<br />";} 
    echo "<br />";
    foreach ($zM as $key => $value){echo "The value at \$zM$key is $value<br />";} 
    echo "Year-Month-Day-Adjusted Timezone Hour-Minute-Seconds ".date("Y-m-d-H-i-", strtotime("+180 minutes"))."00"."<br />";
    
    // $executionEndTime = microtime(true); //measure performance 
    // $seconds = $executionEndTime - $executionStartTime; //measure performance 
    // echo "<br />Took $seconds seconds to execute."; //measure performance 
    // $htmlStr = ob_get_contents(); //output to file
    // ob_end_clean(); //output to file
    // file_put_contents("tmp5.txt", $htmlStr); //output to file
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多