PHP 接下来的Y分钟内,每X分钟的日期和时间是什么?

问题描述 投票:0回答:1

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个回答
0
投票

Windows 10 64位。PHP 7.4.1

PHP 从 floor(date("i") 10) * 10 开始,每 10 分钟在服务器上返回 120 分钟的日期("Y")、日期("m")、日期("d")、日期("H")、日期("i")。

<?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
?>
© www.soinside.com 2019 - 2024. All rights reserved.