gpt4 book ai didi

php - 如何查找两个指定日期之间的日期?

转载 作者:可可西里 更新时间:2023-10-31 22:41:53 24 4
gpt4 key购买 nike

如果我有两个日期 20-4-2010 和 22-4-2010在两个文本框和我希望日期是这样的 20、21、22。我如何得到它?

最佳答案

我很确定这已经被回答了千万亿次,但无论如何:

$start = strtotime('20-04-2010 10:00');
$end = strtotime('22-04-2010 10:00');
for($current = $start; $current <= $end; $current += 86400) {
echo date('d-m-Y', $current);
}

10:00 部分是为了防止代码因夏令时而跳过或重复一天。

通过给出天数:

for($i = 0; $i <= 2; $i++) {
echo date('d-m-Y', strtotime("20-04-2010 +$i days"));
}

使用 PHP5.3

$period = new DatePeriod(
new DateTime('20-04-2010'),
DateInterval::createFromDateString('+1 day'),
new DateTime('23-04-2010') // or pass in just the no of days: 2
);

foreach ( $period as $dt ) {
echo $dt->format( 'd-m-Y' );
}

关于php - 如何查找两个指定日期之间的日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2736784/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com