根据日期获得节气
Posted 6b23
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了根据日期获得节气相关的知识,希望对你有一定的参考价值。
/// <summary> /// 根据日期获得节气 /// </summary> /// <param name="date"></param> /// <returns></returns> public string terms(DateTime date) { string[] SolarTerm = new string[] { "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至" }; int[] sTermInfo = new int[] { 0, 21208, 42467, 63836, 85337, 107014, 128867, 150921, 173149, 195551, 218072, 240693, 263343, 285989, 308563, 331033, 353350, 375494, 397447, 419210, 440795, 462224, 483532, 504758 }; DateTime baseDateAndTime = new DateTime(1900, 1, 6, 2, 5, 0); //#1/6/1900 2:05:00 AM# DateTime newDate; double num; int y; string tempStr = ""; y = date.Year; for (int i = 1; i <= 24; i++) { num = 525948.76 * (y - 1900) + sTermInfo[i - 1]; newDate = baseDateAndTime.AddMinutes(num); if (newDate.DayOfYear == date.DayOfYear) { tempStr = SolarTerm[i - 1]; break; } } return tempStr; }
以上是关于根据日期获得节气的主要内容,如果未能解决你的问题,请参考以下文章
js实现日历可获得指定日期周数及星期几示例分享(js获取星期几)