首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Php/MySQL:时间与当前时间不匹配

问Php/MySQL:时间与当前时间不匹配
EN

Stack Overflow用户
提问于 2017-01-05 04:01:09
回答 0查看 38关注 0票数 0

我创建了一个程序,你输入日期和时间,然后单击提交,它会告诉你输入的日期和时间是否与当前的日期和时间相同。我在时间部分遇到的问题是,无论我投入什么时间,它都会说“同一时间”。date one工作正常,但time one不工作。

代码语言:javascript
复制
<?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>
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41472296

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档