public string getDay() { return((2 == sect) ? lunar.getDayInGanZhiExact2() : lunar.getDayInGanZhiExact()); }
/// <summary> /// 通过八字获取阳历列表 /// </summary> /// <param name="yearGanZhi">年柱</param> /// <param name="monthGanZhi">月柱</param> /// <param name="dayGanZhi">日柱</param> /// <param name="timeGanZhi">时柱</param> /// <param name="sect">流派,2晚子时日柱按当天,1晚子时日柱按明天</param> /// <returns>符合的阳历列表</returns> public static List <Solar> fromBaZi(string yearGanZhi, string monthGanZhi, string dayGanZhi, string timeGanZhi, int sect) { sect = (1 == sect) ? 1 : 2; List <Solar> l = new List <Solar>(); Solar today = new Solar(); Lunar lunar = today.getLunar(); int offsetYear = LunarUtil.getJiaZiIndex(lunar.getYearInGanZhiExact()) - LunarUtil.getJiaZiIndex(yearGanZhi); if (offsetYear < 0) { offsetYear = offsetYear + 60; } int startYear = today.getYear() - offsetYear; int hour = 0; string timeZhi = timeGanZhi.Substring(1); for (int i = 0, j = LunarUtil.ZHI.Length; i < j; i++) { if (LunarUtil.ZHI[i].Equals(timeZhi)) { hour = (i - 1) * 2; } } while (startYear >= SolarUtil.BASE_YEAR - 1) { int year = startYear - 1; int counter = 0; int month = 12; int day; bool found = false; while (counter < 15) { if (year >= SolarUtil.BASE_YEAR) { day = 1; if (year == SolarUtil.BASE_YEAR && month == SolarUtil.BASE_MONTH) { day = SolarUtil.BASE_DAY; } Solar solar = Solar.fromYmdHms(year, month, day, hour, 0, 0); lunar = solar.getLunar(); if (lunar.getYearInGanZhiExact().Equals(yearGanZhi) && lunar.getMonthInGanZhiExact().Equals(monthGanZhi)) { found = true; break; } } month++; if (month > 12) { month = 1; year++; } counter++; } if (found) { counter = 0; month--; if (month < 1) { month = 12; year--; } day = 1; if (year == SolarUtil.BASE_YEAR && month == SolarUtil.BASE_MONTH) { day = SolarUtil.BASE_DAY; } Solar solar = Solar.fromYmdHms(year, month, day, hour, 0, 0); while (counter < 61) { lunar = solar.getLunar(); string dgz = (2 == sect) ? lunar.getDayInGanZhiExact2() : lunar.getDayInGanZhiExact(); if (lunar.getYearInGanZhiExact().Equals(yearGanZhi) && lunar.getMonthInGanZhiExact().Equals(monthGanZhi) && dgz.Equals(dayGanZhi) && lunar.getTimeInGanZhi().Equals(timeGanZhi)) { l.Add(solar); break; } solar = solar.next(1); counter++; } } startYear -= 60; } return(l); }