作者neorange (被罚跪主机板的)
看板Office
标题[算表] google sheet 西历转农历
时间Tue Mar 4 15:35:38 2025
软体:Google Sheet
求教大神!!
使用Google Sheet 西历转农历,以下是ChatGPT给的回答
台湾中央气象署提供官方的农历 API,你可以用它来获取农历日期。
function SolarToLunar(date) {
var year = date.getFullYear();
var month = ('0' + (date.getMonth() + 1)).slice(-2); // 确保是两位数
var day = ('0' + date.getDate()).slice(-2); // 确保是两位数
var url = "
https://www.cwa.gov.tw/Data/js/Calendar/Calendar_" + year +
".json";
try {
var response = UrlFetchApp.fetch(url);
var data = JSON.parse(response.getContentText());
for (var i = 0; i < data.length; i++) {
if (data[i].西元年 == year && data[i].月 == month && data[i].日 == day)
{
return "农历 " + data[i].农历年 + " 年 " + data[i].农历月 + " 月 " +
data[i].农历日 + " 日";
}
}
return "找不到农历日期";
} catch (e) {
return "API 请求失败:" + e.message;
}
}
【执行结果如下】
"API 请求失败:Request failed for
https://www.cwa.gov.tw returned code 404.
Truncated server response: <!DOCTYPE html>
<!--[if IE 8]> <html lang=""zh-Hant-TW"" class=""ie8""> <![endif]-->
<!--[if IE 9]> <html lang=""zh-Hant-TW"" class=""ie9""> <![endif]-->
<... (use muteHttpExceptions option to examine full response)"
404好像是网址不对,请问大神,该怎麽修改呢?
--
┌──────────┐┌──────────┐┌─────────────┐
│
││
││
◢ │
│
◣<○ ○ ◢ ││
◣ ○ ○ ◢ ││
◥ ○ │
│
■︶ /■> ││
/■\ ╰■\ ││
<囧> /█╯ │
│
|| /| ││
|| /| ││
█ ∕) │
└──────────┘└──────────┘└─────────────┘
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 125.229.232.83 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Office/M.1741073746.A.A1B.html
1F:→ suaveness: 你有确定那个网址是存在的吗? ChatGPT有可能会骗你喔 03/04 18:49
2F:→ hwang555: 看到stackoverflow有人是用importxml做可以参考看看 04/08 23:12