{"id":8475,"date":"2024-06-02T18:55:25","date_gmt":"2024-06-02T10:55:25","guid":{"rendered":"https:\/\/0592ban.cn\/?p=8475"},"modified":"2024-06-02T18:55:25","modified_gmt":"2024-06-02T10:55:25","slug":"1992%e5%b9%b4%e5%87%ba%e7%94%9f%e7%9a%84%e7%8e%b0%e5%9c%a8%e5%a4%9a%e5%b0%91%e5%b2%81-1992%e5%b9%b4%e5%87%ba%e7%94%9f%e7%9a%84%e4%bb%8a%e5%b9%b4%e5%a4%9a%e5%a4%a7%e4%ba%86","status":"publish","type":"post","link":"https:\/\/0592ban.cn\/index.php\/2024\/06\/02\/1992%e5%b9%b4%e5%87%ba%e7%94%9f%e7%9a%84%e7%8e%b0%e5%9c%a8%e5%a4%9a%e5%b0%91%e5%b2%81-1992%e5%b9%b4%e5%87%ba%e7%94%9f%e7%9a%84%e4%bb%8a%e5%b9%b4%e5%a4%9a%e5%a4%a7%e4%ba%86\/","title":{"rendered":"1992\u5e74\u51fa\u751f\u7684\u73b0\u5728\u591a\u5c11\u5c81 (1992\u5e74\u51fa\u751f\u7684\u4eca\u5e74\u591a\u5927\u4e86)"},"content":{"rendered":"<p><img decoding=\"async\" alt=\"1992\u5e74\u51fa\u751f\u7684\u73b0\u5728\u591a\u5c11\u5c81\" loading=\"lazy\" src=\"https:\/\/0592ban.cn\/wp-content\/uploads\/2024\/06\/a5cfcc2e-c4b1-45ac-a258-d16b4d2db5ca.jpg\"\/><\/p>\n<p>\n \u8bf7\u8f93\u5165\u60a8\u7684\u51fa\u751f\u65e5\u671f\uff08\u9634\u5386\u6216\u9633\u5386\uff09\uff1a\n<\/p>\n<form>\n <label for=\"birthdate\"><br \/>\n  \u51fa\u751f\u65e5\u671f\uff1a<br \/>\n <\/label><br \/>\n <input id=\"birthdate\" name=\"birthdate\" placeholder=\"\u4f8b\uff1a1992-12-23\" type=\"text\"\/><br \/>\n <input type=\"submit\" value=\"\u8ba1\u7b97\"\/><br \/>\n<\/form>\n<p><script>\n document.addEventListener(\"DOMContentLoaded\", () => {\n      const form = document.querySelector(\"form\");\n      const result = document.querySelector(\"result\");<\/p>\n<p>      form.addEventListener(\"submit\", (event) => {\n        event.preventDefault();<\/p>\n<p>        const birthdate = event.target.querySelector(\"input[name='birthdate']\").value;<\/p>\n<p>        if (!birthdate) {\n          alert(\"\u8bf7\u8f93\u5165\u60a8\u7684\u51fa\u751f\u65e5\u671f\");\n          return;\n        }<\/p>\n<p>        const parts = birthdate.split(\"-\");\n        if (parts.length !== 3) {\n          alert(\"\u51fa\u751f\u65e5\u671f\u683c\u5f0f\u4e0d\u6b63\u786e\");\n          return;\n        }<\/p>\n<p>        const year = parseInt(parts[0]);\n        const month = parseInt(parts[1]);\n        const day = parseInt(parts[2]);<\/p>\n<p>        if (isNaN(year) || isNaN(month) || isNaN(day)) {\n          alert(\"\u51fa\u751f\u65e5\u671f\u683c\u5f0f\u4e0d\u6b63\u786e\");\n          return;\n        }<\/p>\n<p>        let age = 0;\n        if (month === 7 && day === 1) {\n          \/\/ \u65e0\u8bba\u9633\u5386\u9634\u5386\uff0c7\u67081\u65e5\u90fd\u7b97\u751f\u65e5\n          age = calculateAge(year);\n        } else {\n          \/\/ \u5982\u679c\u662f\u9634\u5386\uff0c\u9700\u8981\u6839\u636e\u519c\u5386\u65e5\u671f\u8f6c\u6362\u9633\u5386\u65e5\u671f\uff0c\u518d\u8ba1\u7b97\u5e74\u9f84\n          const lunarDate = new LunarDate(year, month, day);\n          const solarDate = lunarDate.toSolarDate();\n          const solarYear = solarDate.getYear();\n          const solarMonth = solarDate.getMonth();\n          const solarDay = solarDate.getDay();\n          age = calculateAge(solarYear, solarMonth, solarDay);\n        }<\/p>\n<p>        let displayAge = age;\n        if (month > 7 || (month === 7 && day > 1)) {\n          \/\/ \u519c\u5386\u751f\u65e5\u57287\u67081\u65e5\u4e4b\u540e\uff0c\u865a\u5c81\u8981\u52a01\n          displayAge += 1;\n        }<\/p>\n<p>        result.innerHTML = `\u60a8\u7684\u51fa\u751f\u65e5\u671f\u4e3a\uff1a${birthdate}\\n`\n                            + `\u60a8\u7684\u5468\u5c81\u4e3a\uff1a${age}\\n`\n                            + `\u60a8\u7684\u865a\u5c81\u4e3a\uff1a${displayAge}`;\n      });<\/p>\n<p>      function calculateAge(year, month = 1, day = 1) {\n        const currentYear = new Date().getFullYear();\n        const currentMonth = new Date().getMonth();\n        const currentDay = new Date().getDate();<\/p>\n<p>        let age = currentYear - year;\n        if (currentMonth < month || (currentMonth === month &#038;&#038; currentDay < day)) {\n          \/\/ \u751f\u65e5\u8fd8\u6ca1\u5230\uff0c\u5e74\u9f84\u51cf1\n          age -= 1;\n        }\n\n        return age;\n      }\n    });\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u8f93\u5165\u60a8\u7684\u51fa\u751f\u65e5\u671f\uff0c\u9634\u5386\u6216\u9633\u5386\uff0c\u51fa\u751f\u65e5\u671f\uff0cdocument.addEventListener\uff0cDOMContentLoaded\uff0c=\uff0cconstform=document.querySelector\uff0cform\uff0cconstresult=document.querySelector\uff0cresult\uff0cform.addEventLis&#8230;\u3002<\/p>\n","protected":false},"author":1,"featured_media":8474,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4049],"class_list":["post-8475","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-12shengxiao","tag-4049"],"_links":{"self":[{"href":"https:\/\/0592ban.cn\/index.php\/wp-json\/wp\/v2\/posts\/8475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/0592ban.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/0592ban.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/0592ban.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/0592ban.cn\/index.php\/wp-json\/wp\/v2\/comments?post=8475"}],"version-history":[{"count":1,"href":"https:\/\/0592ban.cn\/index.php\/wp-json\/wp\/v2\/posts\/8475\/revisions"}],"predecessor-version":[{"id":8476,"href":"https:\/\/0592ban.cn\/index.php\/wp-json\/wp\/v2\/posts\/8475\/revisions\/8476"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/0592ban.cn\/index.php\/wp-json\/wp\/v2\/media\/8474"}],"wp:attachment":[{"href":"https:\/\/0592ban.cn\/index.php\/wp-json\/wp\/v2\/media?parent=8475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/0592ban.cn\/index.php\/wp-json\/wp\/v2\/categories?post=8475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/0592ban.cn\/index.php\/wp-json\/wp\/v2\/tags?post=8475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}