{"id":52812,"date":"2024-12-03T09:28:26","date_gmt":"2024-12-03T01:28:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52812\/"},"modified":"2024-12-03T09:28:26","modified_gmt":"2024-12-03T01:28:26","slug":"%e5%a6%82%e4%bd%95%e7%94%a8javascript%e7%94%9f%e6%88%90%e4%b8%80%e4%b8%aa%e5%8c%85%e5%90%ab365%e5%a4%a9%e6%97%a5%e6%9c%9f%e5%b9%b6%e5%a1%ab%e5%85%85%e6%8c%87%e5%ae%9a%e6%97%a5%e6%9c%9f%e7%9a%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52812\/","title":{"rendered":"\u5982\u4f55\u7528JavaScript\u751f\u6210\u4e00\u4e2a\u5305\u542b365\u5929\u65e5\u671f\u5e76\u586b\u5145\u6307\u5b9a\u65e5\u671f\u7684\u6570\u7ec4\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u7528JavaScript\u751f\u6210\u4e00\u4e2a\u5305\u542b365\u5929\u65e5\u671f\u5e76\u586b\u5145\u6307\u5b9a\u65e5\u671f\u7684\u6570\u7ec4\uff1f<\/h1>\n<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5206\u4eab\u300a\u5982\u4f55\u7528JavaScript\u751f\u6210\u4e00\u4e2a\u5305\u542b365\u5929\u65e5\u671f\u5e76\u586b\u5145\u6307\u5b9a\u65e5\u671f\u7684\u6570\u7ec4\uff1f\u300b\uff0c\u8986\u76d6\u4e86\u6587\u7ae0\u7684\u5e38\u89c1\u57fa\u7840\u77e5\u8bc6\uff0c\u5176\u5b9e\u4e00\u4e2a\u8bed\u8a00\u7684\u5168\u90e8\u77e5\u8bc6\u70b9\u4e00\u7bc7\u6587\u7ae0\u662f\u4e0d\u53ef\u80fd\u8bf4\u5b8c\u7684\uff0c\u4f46\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u95ee\u9898\uff0c\u8ba9\u8bfb\u8005\u5bf9\u81ea\u5df1\u7684\u638c\u63e1\u7a0b\u5ea6\u6709\u4e00\u5b9a\u7684\u8ba4\u8bc6(B \u6570)\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u66f4\u597d\u7684\u638c\u63e1\u5b83\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241123\/17323551576741a4555816f.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u7528JavaScript\u751f\u6210\u4e00\u4e2a\u5305\u542b365\u5929\u65e5\u671f\u5e76\u586b\u5145\u6307\u5b9a\u65e5\u671f\u7684\u6570\u7ec4\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u7528JavaScript\u751f\u6210\u4e00\u4e2a\u5305\u542b365\u5929\u65e5\u671f\u5e76\u586b\u5145\u6307\u5b9a\u65e5\u671f\u7684\u6570\u7ec4\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u751f\u6210 365 \u5929\u65e5\u671f\u6570\u7ec4\u5e76\u586b\u5145\u5df2\u6709\u65e5\u671f<\/strong><\/p>\n<p>\u5982\u4f55\u7f16\u5199\u4e00\u4e2a javascript \u51fd\u6570\u6765\u751f\u6210\u5305\u542b 365 \u5929\u65e5\u671f\u7684\u6570\u7ec4\uff0c\u5e76\u6839\u636e\u63d0\u4f9b\u7684\u5df2\u6709\u65e5\u671f\u6570\u7ec4\u586b\u5145\u76f8\u5e94\u4f4d\u7f6e\uff1f<\/p>\n<p>\u5047\u8bbe\u5df2\u6709\u65e5\u671f\u6570\u7ec4\u4e3a\uff1a<\/p>\n<pre>let arr = [\"2019\/1\/1\", \"2019\/1\/4\", \"2019\/1\/6\"]<\/pre>\n<p>\u6240\u9700\u7ed3\u679c\u6570\u7ec4\u5e94\u8be5\u5982\u4e0b\uff1a<\/p>\n<pre>result = [\"2019\/1\/1\",,,,,,\"2019\/1\/4\",,,,,\"2019\/1\/6\",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]; \/\/ 365\u4e2a\u6570\u636e<\/pre>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<pre>const arr = [\"2019\/1\/1\", \"2019\/1\/4\", \"2019\/1\/6\"]\n\n\/\/ js \u6839\u636e\u5df2\u6709\u7684\u65e5\u671f\u6570\u7ec4\uff0c\u751f\u6210365\u5929\u7684\u6570\u7ec4\uff0c\u5c06\u5df2\u6709\u7684\u65e5\u671f\u586b\u5199\u5728\u6570\u7ec4\u5bf9\u5e94\u7684\u4f4d\u7f6e\uff0c\u6ca1\u6709\u7684\u65e5\u671f\u586b\u5199\u7a7a\nfunction getDateArray(activeDates) {\n  const dateArray = []\n  for (let i = 0; i &lt; 365; i++) {\n    const date = new Date(2019, 0, 1)  \/\/ 2019\u5e741\u67081\u65e5\n    date.setDate(date.getDate() + i)   \/\/ \u4ece1\u67081\u65e5\u5f00\u59cb\u9010\u4e2a\u589e\u52a0\u5929\u6570\n    const dateStr = date.toLocaleDateString()\n\n    if (activeDates.includes(dateStr)) {\n      dateArray.push(dateStr)\n    } else {\n      dateArray.push('')\n    }\n  }\n  return dateArray\n}\n\nconsole.log(getDateArray(arr));<\/pre>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u5982\u4f55\u7528JavaScript\u751f\u6210\u4e00\u4e2a\u5305\u542b365\u5929\u65e5\u671f\u5e76\u586b\u5145\u6307\u5b9a\u65e5\u671f\u7684\u6570\u7ec4\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u4f7f\u7528 go-sql-driver\/mysql \u5982\u4f55\u83b7\u53d6\u6570\u636e\u5e93\u4e2d\u6ee1\u8db3\u6761\u4ef6\u7684\u603b\u6761\u6570\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u7528JavaScript\u751f\u6210\u4e00\u4e2a\u5305\u542b365\u5929\u65e5\u671f\u5e76\u586b\u5145\u6307\u5b9a\u65e5\u671f\u7684\u6570\u7ec4\uff1f \u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5206\u4eab\u300a\u5982\u4f55\u7528JavaScript\u751f\u6210\u4e00\u4e2a\u5305\u542b365\u5929\u65e5\u671f\u5e76\u586b\u5145\u6307\u5b9a\u65e5\u671f\u7684\u6570\u7ec4\uff1f\u300b\uff0c\u8986\u76d6\u4e86\u6587\u7ae0\u7684\u5e38\u89c1\u57fa\u7840\u77e5\u8bc6\uff0c\u5176\u5b9e\u4e00\u4e2a\u8bed\u8a00\u7684\u5168\u90e8\u77e5\u8bc6\u70b9\u4e00\u7bc7\u6587\u7ae0\u662f\u4e0d\u53ef\u80fd\u8bf4\u5b8c\u7684\uff0c\u4f46\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u95ee\u9898\uff0c\u8ba9\u8bfb\u8005\u5bf9\u81ea\u5df1\u7684\u638c\u63e1\u7a0b\u5ea6\u6709\u4e00\u5b9a\u7684\u8ba4\u8bc6(B \u6570)\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u66f4\u597d\u7684\u638c\u63e1\u5b83\u3002 \u751f\u6210 365 \u5929\u65e5\u671f\u6570\u7ec4\u5e76\u586b\u5145\u5df2\u6709\u65e5\u671f \u5982\u4f55\u7f16\u5199\u4e00\u4e2a javascript \u51fd\u6570\u6765\u751f\u6210\u5305\u542b 365 \u5929\u65e5\u671f\u7684\u6570\u7ec4\uff0c\u5e76\u6839\u636e\u63d0\u4f9b\u7684\u5df2\u6709\u65e5\u671f\u6570\u7ec4\u586b\u5145\u76f8\u5e94\u4f4d\u7f6e\uff1f \u5047\u8bbe\u5df2\u6709\u65e5\u671f\u6570\u7ec4\u4e3a\uff1a let arr = [&#8220;2019\/1\/1&#8221;, &#8220;2019\/1\/4&#8221;, &#8220;2019\/1\/6&#8221;] \u6240\u9700\u7ed3\u679c\u6570\u7ec4\u5e94\u8be5\u5982\u4e0b\uff1a result = [&#8220;2019\/1\/1&#8243;,,,,,,&#8221;2019\/1\/4&#8243;,,,,,&#8221;2019\/1\/6&#8221;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]; \/\/ 365\u4e2a\u6570\u636e \u89e3\u51b3\u65b9\u6848\uff1a const arr = [&#8220;2019\/1\/1&#8221;, &#8220;2019\/1\/4&#8221;, &#8220;2019\/1\/6&#8221;] \/\/ js \u6839\u636e\u5df2\u6709\u7684\u65e5\u671f\u6570\u7ec4\uff0c\u751f\u6210365\u5929\u7684\u6570\u7ec4\uff0c\u5c06\u5df2\u6709\u7684\u65e5\u671f\u586b\u5199\u5728\u6570\u7ec4\u5bf9\u5e94\u7684\u4f4d\u7f6e\uff0c\u6ca1\u6709\u7684\u65e5\u671f\u586b\u5199\u7a7a function getDateArray(activeDates) { const dateArray = [] for (let i = 0; i &lt; 365; i++) { const date = new [&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-52812","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52812","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=52812"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52812\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}