JS日期格式和日期比较 [英] JS date format and date comparison

查看:79
本文介绍了JS日期格式和日期比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种格式的日期

  16-NOV-12 

从id = date的输入框中输入。



如何检查日期是在过去的将来?


< head>
< script src =https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js
type =text / javascript><<<< ; /脚本>
< script src =http://www.datejs.com/build/date.jstype =text / javascript>< / script>
< script type =text / javascript>
$(document).ready(function(){
var idstring =16-NOV-12;
var time = Date.compare(Date.parse(16-NOV-如果(time == 0)now =today;
if(time> 0); Date.today());
var now =in past;
if )now =in future;
alert(idstring +is now + now);
});
< / script>
< / head>
< body>
< / body>
< / html>


I Have a date in this format

 16-NOV-12 

From an input box with id = date.

How do I check if this date is in the past of future?

解决方案

<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>

这篇关于JS日期格式和日期比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆