[英]PHP Time if extends
現在這是我的代碼包含的內容
index.html
<form action="timeout.php" method="POST">
<input type="time" name="txt_time" required>
<input type="submit">
</form>
timeout.php
<?php
$formattedTime = date("h:i A", strtotime($_POST['txt_time']));
$curfew = date("h:i A", strtotime('20:00'));
if($formattedTime > $curfew) {
echo "You are past the curfew time";
} else {
echo "Success";
}
?>
我的問題是,即使我當天參加上午08:00考試,它仍然說您已經過了宵禁時間。 有什么想法嗎?
當您使用$formattedTime > $curfew
比較兩個字符串時, date()
函數將時間戳格式化為字符串,PHP將兩個字符串轉換為整數,這將使8:41 AM
變成8
。
這是一個快速的草率黑客,應該可以正常使用
<?php
$formattedTime = intval(date("Hi", strtotime($_POST['txt_time'])));
$curfew = intval(date("Hi", strtotime('20:00')));
//'H' will get the hour of the time from 0-23, intval will convert that to an integer
if($formattedTime > $curfew) {
echo "You are past the curfew time";
} else {
echo "Success";
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.