gpt4 book ai didi

PHP比较时间

转载 作者:IT王子 更新时间:2023-10-29 01:05:25 25 4
gpt4 key购买 nike

如何在 PHP 中比较时间?

我想说的是:

$ThatTime ="14:08:10";
$todaydate = date('Y-m-d');
$time_now=mktime(date('G'),date('i'),date('s'));
$NowisTime=date('G:i:s',$time_now);
if($NowisTime >= $ThatTime) {
echo "ok";
}

上面的代码没有打印出来。我希望如此。

最佳答案

$ThatTime ="14:08:10";
if (time() >= strtotime($ThatTime)) {
echo "ok";
}

使用 DateTime 的解决方案(也考虑时区)。

$dateTime = new DateTime($ThatTime);
if ($dateTime->diff(new DateTime)->format('%R') == '+') {
echo "OK";
}

http://php.net/datetime.diff

关于PHP比较时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6158726/

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