我创建了一个程序,你输入日期和时间,然后单击提交,它会告诉你输入的日期和时间是否与当前日期和时间相同..我遇到的问题与时间部分是的,无论我什么时候投入,它都说“同一时间”为什么。一天工作正常,但时间不是。
<?php
session_start();
$EntryError=$EntryTimeError="";
if (isset($_POST['submit'])){
$entrydate = $EntryTime = "";
$errorOccured = false;
if (isset($_POST['tsmdate'])){
$entrydate = trim($_POST['tsmdate']);
if (strlen($entrydate) == 0){
$EntryError = "date is missing";
$errorOccured = true;
}
else{
$presentDate=date('Y-m-d');
if(strtotime($entrydate) == strtotime($presentDate))
{
echo "same date";
}
else{
echo "different date";
}
}
}
else{
$EntryError = "date is missing";
}
if (isset($_POST['tsmTime'])){
$EntryTime = trim($_POST['tsmTime']);
if (strlen($EntryTime) == 0){
$EntryTimeError = "time is missing";
$errorOccured = true;
}
else{
$EntryTimeError = "time is missing";
$presentTime= date('h:i A', strtotime($EntryTime));
if(strtotime($EntryTime) == strtotime($presentTime))
{
echo "same time";
}
else{
echo "different time";
}
}
}
else{
$EntrytError = "time is missing";
}
}
?>
<html>
<head>
</head>
<body>
<form name="dates" id="dates" method="POST" action="">
<table cellpadding="5" border="0" width="100%">
<tr>
<td colspan="3" align="center">
<h1> select dates </h1>
</td>
</tr>
<tr>
<td width="30%" align="right">
<label for="tsmdate">Entry date </label>
</td>
<td align="left">
<input type="date" name="tsmdate" id="tsmdate" required="required">
</td>
</tr>
<tr>
<td width="30%" align="right">
<label for="tsmTime">Entry time</label>
</td>
<td align="left">
<input type="time" name="tsmTime" id="tsmTime" required="required">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="submit" value="dates">
</td>
</tr>
</table>
</form>
</body>
</html>
答案 0 :(得分:0)
$presentTime
始终与$EntryTime
相同。这是因为您在日期函数中使用了输入时间。
更改
$presentTime= date('h:i A', strtotime($EntryTime));
到
$presentTime= date('h:i A');