How to convert gregorian date to chinese lunisolar date, no need to explain in detail…
- User
How to convert gregorian date to chinese lunisolar date, no need to explain in detail about chinese calendar, just write an algorithm in javascript
Assistant
Here is a JavaScript function to convert a Gregorian date to Chinese lunisolar date:
function gregorianToChinese(gregorianYear, gregorianMonth, gregorianDay) { // Array of stem-branch pairs for year, month and day const gan = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"]; const zhi = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"]; // Determine lunar year let lunarYear = gregorianYear - 2636; // Determine lunar month let lunarMonth = gregorianMonth; if (gregorianMonth > 2) { lunarMonth -= 2; } else { lunarYear--; lunarMonth += 10; } // Determine lunar day let lunarDay = gregorianDay; // Calculate stem and branch for year, month and day let yIndex = (lunarYear - 1) % 10; let yStem = gan[yIndex]; let yBranch = zhi[(lunarYear - 1) % 12]; let mIndex = (lunarMonth + 9) % 12; let mStem = gan[mIndex]; let mBranch = zhi[mIndex]; let dIndex = (lunarDay - 1) % 12; let dStem = gan[dIndex]; let dBranch = zhi[dIndex]; // Construct Chinese date string let chineseDate = `${lunarYear + 1}年 ${yStem}${yBranch}年 ${mStem}${mBranch}月 ${dStem}${dBranch}日`; return chineseDate; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.