Esempio n. 1
0
        /// <summary>
        /// 通过阳历日期初始化
        /// </summary>
        /// <param name="date">阳历日期</param>
        public Lunar(DateTime date)
        {
            solar = new Solar(date);
            int y = solar.getYear();
            int m = solar.getMonth();
            int d = solar.getDay();
            int startYear, startMonth, startDay;
            int lunarYear, lunarMonth, lunarDay;

            if (y < 2000)
            {
                startYear  = SolarUtil.BASE_YEAR;
                startMonth = SolarUtil.BASE_MONTH;
                startDay   = SolarUtil.BASE_DAY;
                lunarYear  = LunarUtil.BASE_YEAR;
                lunarMonth = LunarUtil.BASE_MONTH;
                lunarDay   = LunarUtil.BASE_DAY;
            }
            else
            {
                startYear  = SolarUtil.BASE_YEAR + 99;
                startMonth = 1;
                startDay   = 1;
                lunarYear  = LunarUtil.BASE_YEAR + 99;
                lunarMonth = 11;
                lunarDay   = 25;
            }
            int diff = 0;

            for (int i = startYear; i < y; i++)
            {
                diff += 365;
                if (SolarUtil.isLeapYear(i))
                {
                    diff += 1;
                }
            }
            for (int i = startMonth; i < m; i++)
            {
                diff += SolarUtil.getDaysOfMonth(y, i);
            }
            diff     += d - startDay;
            lunarDay += diff;
            int lastDate = LunarUtil.getDaysOfMonth(lunarYear, lunarMonth);

            while (lunarDay > lastDate)
            {
                lunarDay  -= lastDate;
                lunarMonth = LunarUtil.nextMonth(lunarYear, lunarMonth);
                if (lunarMonth == 1)
                {
                    lunarYear++;
                }
                lastDate = LunarUtil.getDaysOfMonth(lunarYear, lunarMonth);
            }
            year      = lunarYear;
            month     = lunarMonth;
            day       = lunarDay;
            hour      = solar.getHour();
            minute    = solar.getMinute();
            second    = solar.getSecond();
            dayOffset = LunarUtil.computeAddDays(year, month, day);
            compute();
        }
Esempio n. 2
0
 /// <summary>
 /// 是否闰年
 /// </summary>
 /// <returns>true/false 闰年/非闰年</returns>
 public Boolean isLeapYear()
 {
     return(SolarUtil.isLeapYear(year));
 }