2

我有这种格式的日期

 16-NOV-12 

来自 id = date 的输入框。

我如何检查这个日期是否在未来的过去?

4

2 回答 2

3
<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"
        type="text/javascript"></script>
        <script src="http://www.datejs.com/build/date.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var idstring = "16-NOV-12";
                var time = Date.compare(Date.parse("16-NOV-2012"), Date.today());
                var now = "in past";
                if (time == 0) now = "today";
                if (time > 0) now = "in future";
                alert(idstring + " is " + now);
            });
        </script>
    </head>
    <body>
    </body>
</html>
于 2012-11-20T21:26:28.867 回答
1

尝试这样的事情: -

 var selectedDate = $('16-Nov-12').datepicker('getDate');
 var now = new Date();
 if (selectedDate < now) {
    // selected date is in the past
 }
于 2012-11-20T20:19:51.783 回答