{"id":1710,"date":"2024-11-10T16:33:08","date_gmt":"2024-11-10T08:33:08","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1710\/"},"modified":"2024-11-10T16:33:08","modified_gmt":"2024-11-10T08:33:08","slug":"%e5%a6%82%e4%bd%95%e7%94%a8-javascript-%e4%bb%a3%e7%a0%81%e5%88%a4%e6%96%ad%e4%b8%80%e4%b8%aa%e6%97%a5%e6%9c%9f%e6%98%af%e5%90%a6%e5%9c%a8%e5%bd%93%e5%89%8d%e6%97%b6%e9%97%b4%e4%b9%8b%e5%90%8e","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1710\/","title":{"rendered":"\u5982\u4f55\u7528 JavaScript \u4ee3\u7801\u5224\u65ad\u4e00\u4e2a\u65e5\u671f\u662f\u5426\u5728\u5f53\u524d\u65f6\u95f4\u4e4b\u540e\u7684\u4e5d\u4e2a\u6708\u5185\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173054039894173.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u7528 JavaScript \u4ee3\u7801\u5224\u65ad\u4e00\u4e2a\u65e5\u671f\u662f\u5426\u5728\u5f53\u524d\u65f6\u95f4\u4e4b\u540e\u7684\u4e5d\u4e2a\u6708\u5185\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u7528 JavaScript \u4ee3\u7801\u5224\u65ad\u4e00\u4e2a\u65e5\u671f\u662f\u5426\u5728\u5f53\u524d\u65f6\u95f4\u4e4b\u540e\u7684\u4e5d\u4e2a\u6708\u5185\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5224\u65ad\u65f6\u95f4\u662f\u5426\u7b26\u5408\u7279\u5b9a\u6761\u4ef6<\/strong><\/p>\n<p>\u5982\u4f55\u5728\u7a0b\u5e8f\u4e2d\u68c0\u67e5\u67d0\u4e2a\u65e5\u671f\u662f\u5426\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\uff0c\u4f8b\u5982\u5230\u671f\u65f6\u95f4\u4e0e\u5f53\u524d\u65f6\u95f4\u76f8\u5dee9\u4e2a\u6708\uff1f<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 JavaScript \u4ee3\u7801\u6765\u6bd4\u8f83\u65e5\u671f\uff1a<\/p>\n<pre>const isDistance9 = end =&gt; {\n    const d = new Date(end);\n    const now = new Date();\n    const difMonth = d.getMonth() - now.getMonth();\n    return now.getFullYear() == d.getFullYear() &amp;&amp; difMonth &lt;= 9 &amp;&amp; difMonth &gt;= 0;\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u4e2a\u51fd\u6570\u4e2d\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>end \u662f\u5230\u671f\u65e5\u671f\u5b57\u7b26\u4e32\u3002<\/li>\n<li>d \u662f end \u65e5\u671f\u7684\u65b0\u5b9e\u4f8b\u3002<\/li>\n<li>now \u662f\u5f53\u524d\u65e5\u671f\u7684\u65b0\u5b9e\u4f8b\u3002<\/li>\n<li>difMonth \u662f\u5230\u671f\u65e5\u671f\u6708\u4efd\u51cf\u53bb\u5f53\u524d\u65e5\u671f\u6708\u4efd\u7684\u5dee\u503c\u3002<\/li>\n<li>\n<p>\u51fd\u6570\u8fd4\u56de true\uff0c\u5982\u679c\u4ee5\u4e0b\u6761\u4ef6\u90fd\u6ee1\u8db3\uff1a<\/p>\n<ul>\n<li>now.getFullYear() \u7b49\u4e8e d.getFullYear()\uff08\u5e74\u4efd\u76f8\u540c\uff09<\/li>\n<li>difMonth \u5c0f\u4e8e\u7b49\u4e8e 9\uff08\u5230\u671f\u65e5\u671f\u8ddd\u5f53\u524d\u65e5\u671f\u5c11\u4e8e 9 \u4e2a\u6708\uff09<\/li>\n<li>difMonth \u5927\u4e8e\u7b49\u4e8e 0\uff08\u5230\u671f\u65e5\u671f\u672a\u8d85\u51fa\uff09<\/li>\n<\/ul>\n<p>\u5426\u5219\uff0c\u51fd\u6570\u5c06\u8fd4\u56de false\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u7528 JavaScript \u4ee3\u7801\u5224\u65ad\u4e00\u4e2a\u65e5\u671f\u662f\u5426\u5728\u5f53\u524d\u65f6\u95f4\u4e4b\u540e\u7684\u4e5d\u4e2a\u6708\u5185\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5224\u65ad\u65f6\u95f4\u662f\u5426\u7b26\u5408\u7279\u5b9a\u6761\u4ef6 \u5982\u4f55\u5728\u7a0b\u5e8f\u4e2d\u68c0\u67e5\u67d0\u4e2a\u65e5\u671f\u662f\u5426\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\uff0c\u4f8b\u5982\u5230\u671f\u65f6\u95f4\u4e0e\u5f53\u524d\u65f6\u95f4\u76f8\u5dee9\u4e2a\u6708\uff1f \u89e3\u51b3\u65b9\u6848 \u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 JavaScript \u4ee3\u7801\u6765\u6bd4\u8f83\u65e5\u671f\uff1a const isDistance9 = end =&gt; { const d = new Date(end); const now = new Date(); const difMonth = d.getMonth() &#8211; now.getMonth(); return now.getFullYear() == d.getFullYear() &amp;&amp; difMonth &lt;= 9 &amp;&amp; difMonth &gt;= 0; }; \u767b\u5f55\u540e\u590d\u5236 \u5728\u8fd9\u4e2a\u51fd\u6570\u4e2d\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b end \u662f\u5230\u671f\u65e5\u671f\u5b57\u7b26\u4e32\u3002 d \u662f end \u65e5\u671f\u7684\u65b0\u5b9e\u4f8b\u3002 now \u662f\u5f53\u524d\u65e5\u671f\u7684\u65b0\u5b9e\u4f8b\u3002 difMonth \u662f\u5230\u671f\u65e5\u671f\u6708\u4efd\u51cf\u53bb\u5f53\u524d\u65e5\u671f\u6708\u4efd\u7684\u5dee\u503c\u3002 \u51fd\u6570\u8fd4\u56de [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1710","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=1710"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1710\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}