我创建了一个程序,你输入日期和时间,然后单击提交,它会告诉你输入的日期和时间是否与当前的日期和时间相同。我在时间部分遇到的问题是,无论我投入什么时间,它都会说“同一时间”。date one工作正常,但time one不工作。
<?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>https://stackoverflow.com/questions/41472296
复制相似问题