{"id":1672,"date":"2017-03-23T14:51:56","date_gmt":"2017-03-23T06:51:56","guid":{"rendered":"http:\/\/www.qdabc.cn\/?p=1672"},"modified":"2017-03-23T14:53:26","modified_gmt":"2017-03-23T06:53:26","slug":"js%e6%97%b6%e9%97%b4%e6%af%94%e8%be%83","status":"publish","type":"post","link":"http:\/\/www.qdabc.cn\/?p=1672","title":{"rendered":"js\u65f6\u95f4\u6bd4\u8f83"},"content":{"rendered":"<p>\u628a\u60f3\u8981\u6bd4\u8f83\u7684\u65f6\u95f4\u59822017-3-23\u8f6c\u53d8\u4e3a\u6570\u7ec4\uff0c\u7136\u540e\u7528new Date\uff08\uff09\u8f6c\u4e3a\u53ef\u5bf9\u6bd4\u7684\u6807\u51c6\u65f6\u95f4\u3002<br \/>\n\u7528\u4e00\u4e2a\u65f6\u95f4\u6bd4\u8f83\u51fd\u6570\u5b9e\u73b0\u3002<\/p>\n<pre>&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;meta charset=\"UTF-8\"&gt;\r\n&lt;title&gt;qdabc.cn&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n        &lt;div id=\"nowTime\"&gt;&lt;\/div&gt;\r\n        &lt;div id=\"start\"&gt;\u5f00\u59cb\u65f6\u95f4\u4e3a2017-03-23&lt;\/div&gt;\r\n        &lt;div id=\"startTime\"&gt;&lt;\/div&gt;&lt;!--\u5f53\u524d\u65f6\u95f4\u4e0e\u5f00\u59cb\u65f6\u95f4\uff0c\u8fd4\u56de\u7684\u65f6\u95f4\u6bd4\u8f83\u72b6\u6001--&gt;        \r\n        &lt;div id=\"end\"&gt;\u7ed3\u675f\u65f6\u95f4\u4e3a2019-4-13&lt;\/div&gt;\r\n        &lt;div id=\"endTime\"&gt;&lt;\/div&gt;&lt;!--\u5f53\u524d\u65f6\u95f4\u4e0e\u7ed3\u675f\u65f6\u95f4\uff0c\u8fd4\u56de\u7684\u65f6\u95f4\u6bd4\u8f83\u72b6\u6001--&gt;        \r\n&lt;\/body&gt;\r\n&lt;script&gt;\r\n        function comparaDate(nowArr,dateArr){\/\/\u6bd4\u8f83\u65f6\u95f4\u5927\u5c0f\r\n                var nowDay = new Date(nowArr[0],nowArr[1],nowArr[2]);\/\/\u4f7f\u7528new Date()\u628a\u6570\u7ec4\u8f6c\u5316\u4e3a\u65f6\u95f4\r\n                var day = new Date(dateArr[0],dateArr[1],dateArr[2]);\r\n                \r\n                if(nowDay &lt; day){\/\/nowDay\u6bd4day\u65e9\uff0c\u8fd4\u56de0\r\n                        return 0;\r\n                }\r\n                if(nowDay == day){\/\/nowDay\u4e0eday\u76f8\u7b49\uff0c\u8fd4\u56de1\r\n                        return 1;\r\n                }\r\n                if(nowDay &gt; day){\/\/nowDay\u6bd4day\u665a\uff0c\u8fd4\u56de2\r\n                        return 2;\r\n                }\r\n        }\r\n        var date=new Date();\r\n        var year = date.getFullYear();     \/\/\u5e74   \r\n        var month = date.getMonth() + 1;   \/\/\u6708   \r\n        var day = date.getDate();  \/\/\u65e5\r\n        var nowTimeArr = [year,month,day];\r\n\r\n        var startTime = (year-1)+'-'+month+'-'+day;\/\/\u83b7\u53d6\u65f6\u95f4\uff0c\u53ef\u81ea\u5df1\u5b9a\u4e49\r\n        var startTimeArr = startTime.split('-');\r\n\r\n        var endTime =(year+1)+'-'+month+'-'+day;\/\/\u83b7\u53d6\u65f6\u95f4\uff0c\u53ef\u81ea\u5df1\u5b9a\u4e49\r\n        var endTimeArr = endTime.split('-');\r\n\r\n        var nowToStartStatus = comparaDate(nowTimeArr,startTimeArr);\/\/\u73b0\u5728\u65f6\u95f4\u6bd4\u5f00\u59cb\u65f6\u95f4\r\n        var nowToEndStatus = comparaDate(nowTimeArr,endTimeArr);\/\/\u73b0\u5728\u65f6\u95f4\u6bd4\u7ed3\u675f\u65f6\u95f4\r\n        document.getElementById(\"startTime\").innerHTML=nowToStartStatus;\r\n        document.getElementById(\"endTime\").innerHTML=nowToEndStatus;\r\n        document.getElementById(\"start\").innerHTML='\u5f00\u59cb\u65f6\u95f4\u4e3a'+(year-1)+'-'+month+'-'+day;\r\n        document.getElementById(\"nowTime\").innerHTML='\u5f53\u524d\u65f6\u95f4\u4e3a'+year+'-'+month+'-'+day;\r\n        document.getElementById(\"end\").innerHTML='\u7ed3\u675f\u65f6\u95f4\u4e3a'+(year+1)+'-'+month+'-'+day;\r\n&lt;\/script&gt;\r\n&lt;\/html&gt;<\/pre>\n<p class=\"post-copyright\">\u6b22\u8fce\u5206\u4eab\u672c\u6587\uff0c\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u51fa\u5904\uff1a<a href=\"http:\/\/www.qdabc.cn\">\u524d\u7aefABC<\/a> &raquo; <a href=\"http:\/\/www.qdabc.cn\/?p=1672\">js\u65f6\u95f4\u6bd4\u8f83<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>\u628a\u60f3\u8981\u6bd4\u8f83\u7684\u65f6\u95f4\u59822017-3-23\u8f6c\u53d8\u4e3a\u6570\u7ec4\uff0c\u7136\u540e\u7528new Date\uff08\uff09\u8f6c\u4e3a\u53ef\u5bf9\u6bd4\u7684\u6807\u51c6\u65f6\u95f4\u3002 \u7528\u4e00\u4e2a\u65f6\u95f4\u6bd4\u8f83\u51fd\u6570\u5b9e\u73b0\u3002 &lt;html&gt; &lt;head&gt; &lt;meta cha [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[9,82],"_links":{"self":[{"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/posts\/1672"}],"collection":[{"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1672"}],"version-history":[{"count":3,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/posts\/1672\/revisions"}],"predecessor-version":[{"id":1675,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/posts\/1672\/revisions\/1675"}],"wp:attachment":[{"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1672"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1672"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}