{"id":1148,"date":"2026-01-01T19:19:07","date_gmt":"2026-01-01T11:19:07","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=1148"},"modified":"2026-01-01T19:19:07","modified_gmt":"2026-01-01T11:19:07","slug":"%e6%97%a5%e6%9c%9f%e8%ae%a1%e7%ae%97%e5%99%a8-%e5%a4%a9%e6%95%b0%e8%ae%a1%e7%ae%97%e5%99%a8-%e5%9c%a8%e7%ba%bf%e6%97%a5%e6%9c%9f%e8%ae%a1%e7%ae%97%e5%b7%a5%e5%85%b7","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2026\/01\/01\/%e6%97%a5%e6%9c%9f%e8%ae%a1%e7%ae%97%e5%99%a8-%e5%a4%a9%e6%95%b0%e8%ae%a1%e7%ae%97%e5%99%a8-%e5%9c%a8%e7%ba%bf%e6%97%a5%e6%9c%9f%e8%ae%a1%e7%ae%97%e5%b7%a5%e5%85%b7\/","title":{"rendered":"\u65e5\u671f\u8ba1\u7b97\u5668\u00a0&#8211; \u5929\u6570\u8ba1\u7b97\u5668 | \u5728\u7ebf\u65e5\u671f\u8ba1\u7b97\u5de5\u5177"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html>\n&lt;html lang=\"zh-CN\">\n&lt;head>\n&lt;meta charset=\"UTF-8\">\n&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n&lt;title>\u9ad8\u7ea7\u65e5\u671f\u8ba1\u7b97\u5668\uff08\u542b\u8282\u5047\u65e5\uff09&lt;\/title>\n&lt;style>\nbody {\n  font-family: Arial, sans-serif;\n  background-color: #f0f2f5;\n  display: flex;\n  justify-content: center;\n  padding-top: 40px;\n}\n.container {\n  background-color: #fff;\n  padding: 25px 35px;\n  border-radius: 8px;\n  box-shadow: 0 5px 15px rgba(0,0,0,0.1);\n  width: 380px;\n}\nh1 {\n  text-align: center;\n  color: #333;\n}\nlabel {\n  display: block;\n  margin: 12px 0 5px;\n  font-weight: bold;\n}\ninput&#91;type=\"date\"], input&#91;type=\"number\"], textarea {\n  width: 100%;\n  padding: 8px 10px;\n  border-radius: 4px;\n  border: 1px solid #ccc;\n  font-size: 15px;\n}\ntextarea {\n  height: 60px;\n}\nbutton {\n  margin-top: 15px;\n  width: 100%;\n  padding: 10px;\n  font-size: 16px;\n  background-color: #4CAF50;\n  color: white;\n  border: none;\n  border-radius: 4px;\n  cursor: pointer;\n}\nbutton:hover { background-color: #45a049; }\n.result {\n  margin-top: 15px;\n  font-size: 16px;\n  color: #333;\n}\n.checkbox-container {\n  margin-top: 10px;\n}\nhr {\n  margin:20px 0;\n}\n&lt;\/style>\n&lt;\/head>\n&lt;body>\n\n&lt;div class=\"container\">\n  &lt;h1>\u9ad8\u7ea7\u65e5\u671f\u8ba1\u7b97\u5668&lt;\/h1>\n\n  &lt;!-- \u76ee\u6807\u65e5\u671f\u8ba1\u7b97 -->\n  &lt;label for=\"startDate\">\u8d77\u59cb\u65e5\u671f:&lt;\/label>\n  &lt;input type=\"date\" id=\"startDate\">\n\n  &lt;label for=\"days\">\u589e\u52a0\/\u51cf\u5c11\u5929\u6570:&lt;\/label>\n  &lt;input type=\"number\" id=\"days\" placeholder=\"\u53ef\u8f93\u5165\u6b63\u6570\u6216\u8d1f\u6570\">\n\n  &lt;div class=\"checkbox-container\">\n    &lt;input type=\"checkbox\" id=\"excludeWeekends\">\n    &lt;label for=\"excludeWeekends\">\u6392\u9664\u5468\u672b&lt;\/label>\n  &lt;\/div>\n\n  &lt;label for=\"holidays\">\u8282\u5047\u65e5\uff08YYYY-MM-DD\uff0c\u6bcf\u884c\u4e00\u4e2a\uff09:&lt;\/label>\n  &lt;textarea id=\"holidays\" placeholder=\"\u4f8b\u5982\uff1a2026-01-01\">&lt;\/textarea>\n\n  &lt;button onclick=\"calculateTargetDate()\">\u8ba1\u7b97\u76ee\u6807\u65e5\u671f&lt;\/button>\n  &lt;div class=\"result\" id=\"targetResult\">&lt;\/div>\n\n  &lt;hr>\n\n  &lt;!-- \u65e5\u671f\u5dee\u8ba1\u7b97 -->\n  &lt;label for=\"date1\">\u5f00\u59cb\u65e5\u671f:&lt;\/label>\n  &lt;input type=\"date\" id=\"date1\">\n\n  &lt;label for=\"date2\">\u7ed3\u675f\u65e5\u671f:&lt;\/label>\n  &lt;input type=\"date\" id=\"date2\">\n\n  &lt;div class=\"checkbox-container\">\n    &lt;input type=\"checkbox\" id=\"excludeWeekendsDiff\">\n    &lt;label for=\"excludeWeekendsDiff\">\u6392\u9664\u5468\u672b&lt;\/label>\n  &lt;\/div>\n\n  &lt;label for=\"holidaysDiff\">\u8282\u5047\u65e5\uff08YYYY-MM-DD\uff0c\u6bcf\u884c\u4e00\u4e2a\uff09:&lt;\/label>\n  &lt;textarea id=\"holidaysDiff\" placeholder=\"\u4f8b\u5982\uff1a2026-01-01\">&lt;\/textarea>\n\n  &lt;button onclick=\"calculateDateDiff()\">\u8ba1\u7b97\u65e5\u671f\u5dee&lt;\/button>\n  &lt;div class=\"result\" id=\"diffResult\">&lt;\/div>\n&lt;\/div>\n\n&lt;script>\nfunction parseHolidays(text) {\n  return text.split('\\n').map(s => s.trim()).filter(s => s).map(s => new Date(s).toDateString());\n}\n\n\/\/ \u76ee\u6807\u65e5\u671f\u8ba1\u7b97\nfunction calculateTargetDate() {\n  const startDateInput = document.getElementById('startDate').value;\n  const daysInput = parseInt(document.getElementById('days').value);\n  const excludeWeekends = document.getElementById('excludeWeekends').checked;\n  const holidays = parseHolidays(document.getElementById('holidays').value);\n\n  if (!startDateInput) { alert('\u8bf7\u9009\u62e9\u8d77\u59cb\u65e5\u671f'); return; }\n  if (isNaN(daysInput)) { alert('\u8bf7\u8f93\u5165\u6709\u6548\u5929\u6570'); return; }\n\n  let currentDate = new Date(startDateInput);\n  let daysRemaining = Math.abs(daysInput);\n  const step = daysInput >= 0 ? 1 : -1;\n\n  while (daysRemaining > 0) {\n    currentDate.setDate(currentDate.getDate() + step);\n    const dayStr = currentDate.toDateString();\n\n    if (excludeWeekends) {\n      const day = currentDate.getDay();\n      if (day === 0 || day === 6) continue; \/\/ \u8df3\u8fc7\u5468\u672b\n    }\n    if (holidays.includes(dayStr)) continue; \/\/ \u8df3\u8fc7\u8282\u5047\u65e5\n\n    daysRemaining--;\n  }\n\n  const yyyy = currentDate.getFullYear();\n  const mm = String(currentDate.getMonth() + 1).padStart(2, '0');\n  const dd = String(currentDate.getDate()).padStart(2, '0');\n\n  document.getElementById('targetResult').innerText = `\u8ba1\u7b97\u7ed3\u679c\u65e5\u671f: ${yyyy}-${mm}-${dd}`;\n}\n\n\/\/ \u65e5\u671f\u5dee\u8ba1\u7b97\nfunction calculateDateDiff() {\n  const date1Input = document.getElementById('date1').value;\n  const date2Input = document.getElementById('date2').value;\n  const excludeWeekends = document.getElementById('excludeWeekendsDiff').checked;\n  const holidays = parseHolidays(document.getElementById('holidaysDiff').value);\n\n  if (!date1Input || !date2Input) { alert('\u8bf7\u9009\u62e9\u4e24\u4e2a\u65e5\u671f'); return; }\n\n  let d1 = new Date(date1Input);\n  let d2 = new Date(date2Input);\n  if (d1 > d2) &#91;d1, d2] = &#91;d2, d1];\n\n  let diffDays = 0;\n  let tempDate = new Date(d1);\n\n  while (tempDate &lt;= d2) {\n    const day = tempDate.getDay();\n    const dayStr = tempDate.toDateString();\n    if ((!excludeWeekends || (day !== 0 &amp;&amp; day !== 6)) &amp;&amp; !holidays.includes(dayStr)) {\n      diffDays++;\n    }\n    tempDate.setDate(tempDate.getDate() + 1);\n  }\n\n  document.getElementById('diffResult').innerText = `\u76f8\u5dee\u5929\u6570: ${diffDays} \u5929`;\n}\n&lt;\/script>\n\n&lt;\/body>\n&lt;\/html>\n<\/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":[12],"tags":[],"class_list":["post-1148","post","type-post","status-publish","format-standard","hentry","category-12"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=1148"}],"version-history":[{"count":2,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1148\/revisions"}],"predecessor-version":[{"id":1150,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1148\/revisions\/1150"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=1148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=1148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=1148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}