コード例 #1
0
ファイル: Class1.cs プロジェクト: nokia6102/109BigDataAi
    public static string useTaiwanLC(DateTime date)
    {
        string TeanGean = "甲乙丙丁戊己庚辛壬癸";
        string DeGe     = "子丑寅卯辰巳午未申酉戌亥";
        string CAnimal  = "鼠牛虎兔龍蛇馬羊猴雞狗豬";

        TaiwanLunisolarCalendar Tlc = new TaiwanLunisolarCalendar();
        //DateTime dtNow = new DateTime.Now();//拿今年的日期
        //DateTime.Now.AddYears;


        int lun60Year = Tlc.GetSexagenaryYear(date.AddYears(0));
        //  int lun60Year = Tlc.GetSexagenaryYear(DateTime.Now.AddYears(0));
        int TeanGeanYear = Tlc.GetCelestialStem(lun60Year) - 1;
        int DeGeYear     = Tlc.GetTerrestrialBranch(lun60Year) - 1;

        int lunMonth  = Tlc.GetMonth(DateTime.Now.AddYears(0));
        int leapMonth = Tlc.GetLeapMonth(Tlc.GetYear(DateTime.Now.AddYears(0)));

        if (leapMonth > 0 && lunMonth >= leapMonth)
        {
            //lunMonth = lunMonth - 1;
            lunMonth -= 1;
        }
        int lunDay = Tlc.GetDayOfMonth(DateTime.Now.AddYears(0));

        //Console.WriteLine("debug" + TeanGean[TeanGeanYear] + DeGe[DeGeYear] + CAnimal[DeGeYear]);
        Console.WriteLine("驗算網頁 : http://tlcheng.twbbs.org/Model/Online/LunarCalendar/Default.aspx");
        Console.WriteLine("參考資料 : http://anita-lo.blogspot.com/2008/03/net_20.html");
        Console.WriteLine("查表法   : http://chmis.cca.gov.tw/chmp/blog/a571024/myBlogArticleAction.do?method=doListArticleByPk&articleId=3213");
        Console.WriteLine("參考資料 : http://www.fushantang.com/1003/c1007.html");
        //return String.Format("農曆:{0}年{1}月{2}日", TeanGean[TeanGeanYear] & DeGe[DeGeYear], lunMonth, lunDay);
        //return String.Format("農曆:{0}年{1}月{2}日 今年的生肖: {3}",Tlc.GetYear(DateTime.Now).ToString(), lunMonth, lunDay, CAnimal[DeGeYear].ToString());
        return(String.Format("{0}", CAnimal[DeGeYear].ToString()));
    }
コード例 #2
0
        /// <summary>
        /// 取得天干地支年月日
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static string GetTaiwanHeaEarDate(this DateTime dt)
        {
            string teanGean             = "甲乙丙丁戊己庚辛壬癸";
            string deGe                 = "子丑寅卯辰巳午未申酉戌亥";
            TaiwanLunisolarCalendar tlc = new TaiwanLunisolarCalendar();
            int lun60Year               = tlc.GetSexagenaryYear(DateTime.Now.AddYears(0));
            int TeanGeanYear            = tlc.GetCelestialStem(lun60Year) - 1;
            int DeGeYear                = tlc.GetTerrestrialBranch(lun60Year) - 1;
            int lunMonth                = tlc.GetMonth(DateTime.Now.AddYears(0));
            int leapMonth               = tlc.GetLeapMonth(tlc.GetYear(DateTime.Now.AddYears(0)));

            if (leapMonth > 0 && lunMonth >= leapMonth)
            {
                lunMonth -= 1;
            }
            int lunDay = tlc.GetDayOfMonth(DateTime.Now.AddYears(0));

            return(String.Format("{0}年{1}月{2}日", teanGean[TeanGeanYear].ToString() + deGe[DeGeYear].ToString(), lunMonth, lunDay));
        }
コード例 #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;
    }