gpt4 book ai didi

PHP 检查是否过了 10 分钟

转载 作者:太空宇宙 更新时间:2023-11-03 11:39:41 24 4
gpt4 key购买 nike

我想比较两个日期,看看是否已经过了 10 分钟。

这是我得到的代码,但我不太清楚如何去做。

我从我的表中获取第一个日期(保存为 timestamp,例如:2017-03-26 22:33:45)然后我想将它与 time现在

$sql = "SELECT saved_time from table1 where email = '$email'";
$stmt = $conn->prepare($sql);
$stmt->execute();
while($row = $stmt->fetch()) {
$savedTime = $row[0];
}
$now = time();
if (/*10 minutes has passed between saved time and now*/) {
echo "Your account is unlocked";
} else if (/*10 minutes hasn't passed*/) {
echo "Your account is locked";
}

最佳答案

试试这段代码:

    $timezone = "Asia/Kolkata";// Select Timezone as of your Preference or MySQL Server Timezone
date_default_timezone_set($timezone);
$sql = "SELECT saved_time from table1 where email = :email";
$stmt = $conn->prepare($sql);
$stmt->execute(array(':email' => $email));
while($row = $stmt->fetch()) {
$savedTime = $row[0];
}

// Uncomment below Line if $savedTime is in MySQL DATETIME Format
// $savedTime = strtotime($savedTime);
$now = time();

if (round(($now - $savedTime) / 60,2) >= 10){
echo "Your account is unlocked";
} elseif (round(($now - $savedTime) / 60,2) < 10){
echo "Your account is locked";
}

关于PHP 检查是否过了 10 分钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43034061/

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