代码之家  ›  专栏  ›  技术社区  ›  nacho4d

怎么知道今天是几号?

  •  22
  • nacho4d  · 技术社区  · 14 年前

    我正在尝试,但不起作用…为什么?

    <html>
    <body>
        <script type="text/javascript">
    
            var today=new Date(); //today is Nov 28, 2010
            today.setHours(0);
            today.setMinutes(0);
            today.setSeconds(0);
            document.write(today+" ");
    
            var today2 = new Date("November 28, 2010");
            document.write(today2 + " ");
            if (today == today2) { document.write("==");
            if (!(today > today2) && !(today < today2) ) {document.write("==  ");}
            if (today > today2) { document.write(">  ");}
            if (today >= today2 ){ document.write(">=  ");}
            if (today < today2 ) { document.write("<  ");}
            if (today <= today2 ){ document.write("<=  ");}
    
        </script>
    </body>
    </html>
    

    我总是明白:

    Sun Nov 28 2010 00:00:00 GMT+0900 (JST) Sun Nov 28 2010 00:00:00 GMT+0900 (JST) > >=
    

    两个日期不一样吗?因此,我应该 == 已打印但未发生…(

    感谢您的帮助。

    2 回复  |  直到 14 年前
        1
  •  67
  •   Shashank Agrawal    8 年前

    Date

    .toDateString()

    today.toDateString() == today2.toDateString();  // true
    

    today == new Date( today );  // false
    

    false

        2
  •  20
  •   Kalamarico Gopakumar AP    7 年前
    function today(td) {
        var d = new Date();
        return td.getDate() == d.getDate() && td.getMonth() == d.getMonth() && td.getFullYear() == d.getFullYear();
    }