Пример #1
0
        /// <summary>
        /// Convert the DateTime object to TaiwanLunisolarCalendar's DateTime format.
        /// For example: 2008/1/26 will become 96/12/19
        /// </summary>
        public static DateTime ToTaiwanLunisolarDateTime(this DateTime d)
        {
            TaiwanLunisolarCalendar tlc = new TaiwanLunisolarCalendar();

            DateTime result = new DateTime(tlc.GetYear(d), tlc.GetMonth(d), tlc.GetDayOfMonth(d), d.Hour, d.Minute, d.Second, d.Millisecond);

            return(result);
        }
Пример #2
0
 public static void TaiwanLunisolarTest()
 {
     TaiwanLunisolarCalendar tc = new TaiwanLunisolarCalendar();
     Assert.Equal(1, tc.Eras.Length);
 }
Пример #3
0
    public string GetLunarDate(DateTime mdate, string mtype)
    {
        String_Func sfc = new String_Func();
        TaiwanLunisolarCalendar tlc = new TaiwanLunisolarCalendar();

        string ldate = "";
        int LunarYear = 0;										// 農曆年
        int LunarMonth = 0;										// 月份
        int LunarDay = 0;										// 日期
        int LunarHour = 0;										// 時
        int LunarMin = 0;										// 分
        int LunarSec = 0;										// 秒
        int LeapMonth = 0;										// 潤月

        LunarYear = tlc.GetSexagenaryYear(mdate);				// 取得西元年

        #region 農曆年
        if (mtype.Contains("y"))
        {
            ldate = GetHeavenlyStem(tlc.GetCelestialStem(LunarYear));					// 年 - 天干
            ldate += GetEarthlyBranch(tlc.GetTerrestrialBranch(LunarYear)) + "年";		// 年 - 地支
        }
        #endregion

        #region 農曆月
        if (mtype.Contains("M"))
        {
            LunarMonth = tlc.GetMonth(mdate);						// 取得月份
            LeapMonth = tlc.GetLeapMonth(tlc.GetYear(mdate));		// 取得潤月

            if (LeapMonth > 0)
            {
                // 當年有潤月,月份會出現13個月,在潤月之後的月分要減一。
                if (LeapMonth == LunarMonth)
                {
                    ldate += "閏" + GetChMonth(LeapMonth - 1) + "月";
                }
                else if (LunarMonth > LeapMonth)
                {
                    ldate += GetChMonth(LunarMonth - 1) + "月";
                }
                else
                    ldate += GetChMonth(LunarMonth) + "月";
            }
            else
                ldate += GetChMonth(LunarMonth) + "月";
        }
        #endregion

        #region 農曆日
        if (mtype.Contains("d"))
        {
            LunarDay = tlc.GetDayOfMonth(mdate);

            ldate += GetChDay(LunarDay) + "日";
        }
        #endregion

        #region 農曆時 (子、丑...)
        if (mtype.Contains("H"))
        {
            LunarHour = tlc.GetHour(mdate);
            ldate += GetChHour(LunarHour) + "時";
        }
        #endregion

        #region 中文數字時 (五、十一...)
        if (mtype.Contains("h"))
        {
            LunarHour = tlc.GetHour(mdate);
            ldate += GetChNHour(LunarHour) + "時";
        }
        #endregion

        #region 農曆分
        if (mtype.Contains("m"))
        {
            LunarMin = tlc.GetMinute(mdate);
            ldate += sfc.GetChNumber((ulong)LunarMin).Replace("一十", "十") + "分";
        }
        #endregion

        #region 農曆秒
        if (mtype.Contains("s"))
        {
            LunarSec = tlc.GetSecond(mdate);
            if (LunarSec == 0)
            {
                ldate += "整";
            }
            else
            {
                ldate += sfc.GetChNumber((ulong)LunarSec).Replace("一十", "十") + "秒";
            }
        }
        #endregion

        return ldate;
    }
Пример #4
0
    public string GetDateLunarZodiac(DateTime mdate)
    {
        TaiwanLunisolarCalendar tlc = new TaiwanLunisolarCalendar();

        return GetLunarZodiac(tlc.GetTerrestrialBranch(tlc.GetSexagenaryYear(mdate)));
    }