{"id":72,"date":"2021-07-30T14:45:47","date_gmt":"2021-07-30T06:45:47","guid":{"rendered":"http:\/\/blog.nonot.cn\/?p=72"},"modified":"2024-07-08T12:56:43","modified_gmt":"2024-07-08T04:56:43","slug":"js%e8%ae%a1%e7%ae%97%e5%ae%9e%e9%99%85%e8%af%b7%e5%81%87%e5%a4%a9%e6%95%b0","status":"publish","type":"post","link":"https:\/\/blog.nonot.cn\/index.php\/2021\/07\/30\/js%e8%ae%a1%e7%ae%97%e5%ae%9e%e9%99%85%e8%af%b7%e5%81%87%e5%a4%a9%e6%95%b0\/","title":{"rendered":"js\u8ba1\u7b97\u5b9e\u9645\u8bf7\u5047\u5929\u6570"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>&lt;html>\n&lt;head>\n&lt;script language=\"JavaScript\">\n\/*&lt;!--\n \n  function compdate(st1,ed1){\n        var st,ed,aaa,bbb,st2;\n        aaa = st1.split(\"-\");\/\/alert(aaa);\n        bbb = ed1.split(\"-\");\/\/alert(bbb);\n        st = new Date(aaa[0],(aaa[1]-1),aaa[2],\"00\",\"00\",\"00\");  \/\/alert(aaa[2]);\n        ed = new Date(bbb[0],(bbb[1]-1),bbb[2],\"00\",\"00\",\"00\");  \/\/alert(ed);    \n        var tmp   =   86400000;     \n        var   days   =   Math.round((ed.getTime()   -   st.getTime())\/tmp);alert(days);   \/\/\u76f8\u9694\u7684\u5929\u6570   \n        var   workDays=   0;\/\/\u5de5\u4f5c\u65e5   \n        var   holiday   =   new   Array(\"2-27\",\"10-03\",\"10-02\"); \/\/alert(holiday);\/\/\u81ea\u884c\u6dfb\u52a0\u5047\u65e5\n        var    uuu =    new   Array(\"\u65e5\",\"\u4e00\",\"\u4e8c\",\"\u4e09\",\"\u56db\",\"\u4e94\",\"\u516d\");\n        for(var   i   =1;i&lt;=(days-1);i++)   \n        {\n              \/\/alert(i);\n              st2 =new Date();   \n              st2.setTime(st.getTime()+tmp*i);   \/\/   i   \u5929\u4ee5\u540e\u7684\u65e5\u671f     \n              \/\/alert(st2);\n              \/\/alert(uuu[st2.getDay()]);\n              if(st2.getDay()!=0   &amp;&amp;   st2.getDay()!=6)   \/\/\u4e0d\u662f\u5468\u516d\u3001\u5468\u65e5   \n              {   \n \n                  var   str   =   (st2.getMonth()+1)+\"-\"+st2.getDate();   \n                  if(holiday.toString().indexOf(str)   &lt;   0)   \/\/\u4e0d\u662f\u81ea\u5b9a\u4e49\u7684\u5047\u65e5   \n                      {   \n                        \/\/alert(str);\n\t\t\t\t\t\talert(holiday+'=='+str);\n                        workDays++;   \n                      }   \n              }   \n          }\n           alert(workDays);  \n          return   workDays;\/\/\u8fd4\u56de\u5de5\u4f5c\u65e5\n         \n  }\n \/\/http:\/\/www.w3schools.com\/jS\/tryit.asp?filename=tryjs_timing_clock   \n  compdate(\"2020-2-26\",\"2020-3-3\");\n--> *\/ \n&lt;\/script>\n&lt;script language=\"JavaScript\">\n&lt;!--\n \n  function compdate(st1,ed1,st2,ed2){\n        var st,ed,aaa,bbb,st2;\n        aaa = st1.split(\"-\");\/\/alert(aaa);\n        bbb = ed1.split(\"-\");\/\/alert(bbb);\n        st = new Date(aaa[0],(aaa[1]-1),aaa[2],\"00\",\"00\",\"00\");  \/\/alert(aaa[2]);\n        ed = new Date(bbb[0],(bbb[1]-1),bbb[2],\"00\",\"00\",\"00\");  \/\/alert(ed);    \n        var tmp   =   86400000;     \n        var   days   =   Math.round((ed.getTime()   -   st.getTime())\/tmp);alert(days);   \/\/\u76f8\u9694\u7684\u5929\u6570   \n        var   workDays=   0;\/\/\u5de5\u4f5c\u65e5   \n        var   holiday   =   new   Array(\"2-27\",\"10-03\",\"10-02\"); \/\/alert(holiday);\/\/\u81ea\u884c\u6dfb\u52a0\u5047\u65e5\n        var    uuu =    new   Array(\"\u65e5\",\"\u4e00\",\"\u4e8c\",\"\u4e09\",\"\u56db\",\"\u4e94\",\"\u516d\");\n        for(var   i   =1;i&lt;=(days-1);i++)   \n        {\n              \/\/alert(i);\n              st2 =new Date();   \n              st2.setTime(st.getTime()+tmp*i);   \/\/   i   \u5929\u4ee5\u540e\u7684\u65e5\u671f     \n              \/\/alert(st2);\n              \/\/alert(uuu[st2.getDay()]);\n              if(st2.getDay()!=0   &amp;&amp;   st2.getDay()!=6)   \/\/\u4e0d\u662f\u5468\u516d\u3001\u5468\u65e5   \n              {   \n \n                  var   str   =   (st2.getMonth()+1)+\"-\"+st2.getDate();   \n                  if(holiday.toString().indexOf(str)   &lt;   0)   \/\/\u4e0d\u662f\u81ea\u5b9a\u4e49\u7684\u5047\u65e5   \n                      {   \n                        \/\/alert(str);\n\t\t\t\t\t\talert(holiday+'=='+str);\n                        workDays++;   \n                      }   \n              }   \n          }\n\t\t  \n          if(st2==1){\n              workDays=workDays+0.5;\n          }else{\n              workDays=workDays+1;\n          }\n\t\t  if(ed2==1){\n              workDays=workDays+1;\n          }else{\n              workDays=workDays+0.5;\n          }\n          alert(workDays);  \n          return   workDays;\/\/\u8fd4\u56de\u5de5\u4f5c\u65e5\n         \n  }\n \/\/http:\/\/www.w3schools.com\/jS\/tryit.asp?filename=tryjs_timing_clock   \n  compdate(\"2020-2-26\",\"2020-3-3\",0,0);\n-->  \n&lt;\/script>\n&lt;\/head>\n&lt;body>\n&lt;\/body>\n&lt;\/html><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-72","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/72","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/comments?post=72"}],"version-history":[{"count":1,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/72\/revisions"}],"predecessor-version":[{"id":1233,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/72\/revisions\/1233"}],"wp:attachment":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/media?parent=72"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/categories?post=72"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/tags?post=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}