算法求公历公历我正在做一个驱动来计算给定时间跨度内的各种假期。所以,我需要找到所有中国假期(农历新年、清明节、端午节等)的公历。我使用著名的“复活节算法”进行耶稣受难日、复活节星期一、耶稣升天日和圣灵降临节星期一的计算;但是,我不太了解中国的日历。我发现了类似的问题,但它们通常是从公历到中文:Lunar/Lunarphasealgorithmtocalculatelunar/yin-yangholidaysinpythonhttp://www.herongyang.com/year/program.htmlhttp://www.hermetic.ch/cal_stud/ch_year.htm最后一个链接非常有用,但我仍然不确定如何以对我有帮助的方式实现该算法。任何建议或代码将不胜感激!这是我的耶稣受难日算法:privatevoidGetGoodFridayOccurances(DateTimestartDate,DateTimeendDate,ListobservedHolidays,StandardHolidayholiday){for(DateTimedate=startDate;date10)tA=tA-1;//查找下周日inttB=(tA-19)%7;inttC=(40-firstTwo)%4;如果(tC==3||tC>1)tC=tC+1;pfmDate=date.Year%100;inttD=(pfmDate+pfmDate/4)%7;inttE=((20-tB-tC-tD)%7)+1;天=tA+tE;如果(天>31){天=天-31;月=4;}else{月=3;}#endregionDateTimeobserved=newDateTime(date.Year,month,day).AddDays(-2);ObservedHolidayobsdate=newObservedHoliday(假日);if(startDate==endDate&&startDate.Day==observed.Day){obsdate.DateObserved=observed;observedHolidays.Add(obsdate);}elseif(startDate!=endDate&&observed>=startDate){obsdate.DateObserved=observed;observedHolidays.Add(obsdate);对于中国新年,我认为这会起作用:ChineseLunisolarCalendarchinese=newChineseLunisolarCalendar();公历日历grgorian=new公历日历();日期时间utcNow=DateTime.UtcNow;//获取当前UTC日期/时间的农历新年DateTimechineseNewYear=chinese.ToDateTime(utcNow.Year,1,1,0,0,0,0);//转换回公历(您可以直接查询`chineseNewYear`的属性,但为了保持一致性,我更喜欢使用`GregorianCalendar`:Int32year=gregorian.GetYear(chineseNewYear);Int32month=gregorian.GetMonth(chineseNewYear);Int32day=gregorian.GetDayOfMonth(chineseNewYear);由于中国历法非常复杂(并且基于天文考虑),因此没有简单的方法来计算农历新年的公历日期,而事实并非如此(有一些多年来总是会失败的“经验法则”。)对于基本理论,请参见此处,对于Windows软件(以及其他农历计算),请参见此处农历新年公历算法共享的所有内容公历,如果对你有用,需要了解更多C#学习教程,希望大家多多关注。本文收集自网络,不代表立场,如涉及侵权,请点击右边联系管理被会员删除。如需转载请注明出处:
