Example #1
0
    //int GetSexagenaryYear (DateTime time) 获取指定公历日期的农历年份的干支纪年
    //int GetSexagenaryYear (DateTime time) 获取指定公历日期的农历年份的干支纪年,从1到60,分别是甲子、乙丑、丙寅、….癸亥, 比如戊戌变法、辛亥革命就是按这个来命名的。当然算八字也少不了这个。
    //nt GetTerrestrialBranch (int sexagenaryYear) ) 获取一个干支的地支,, 从1到12, 表示子、丑、寅、…今年是狗年,
    public string GetStemBranch(DateTime time)
    {
        int    sexagenaryYear = calendar.GetSexagenaryYear(time);
        string stemBranch     = CelestialStem.Substring(calendar.GetCelestialStem(sexagenaryYear) - 1, 1) + TerrestrialBranch.Substring(calendar.GetTerrestrialBranch(sexagenaryYear) - 1, 1);

        return(stemBranch);
    }
Example #2
0
        /// <summary>
        /// 获取十二生肖
        /// </summary>
        /// <param name="aDateTime"></param>
        /// <returns></returns>
        public static string Get12Lunar(DateTime aDateTime)
        {
            System.Globalization.ChineseLunisolarCalendar chinseCaleander = new System.Globalization.ChineseLunisolarCalendar();
            string TreeYear = "鼠牛虎兔龙蛇马羊猴鸡狗猪";
            int    intYear  = chinseCaleander.GetSexagenaryYear(aDateTime);

            return(I3StringUtil.SubString(TreeYear, chinseCaleander.GetTerrestrialBranch(intYear) - 1, 1));
        }
        /// <summary>
        /// 获取生肖,要求传入阳历的年月日
        /// </summary>
        /// <param name="year">年</param>
        /// <param name="month">月</param>
        /// <param name="day">日</param>
        /// <returns>生肖</returns>
        public static string GetYearOfBirth(string year, string month, string day) {

            var chineseCalender = new ChineseLunisolarCalendar();
            // 使用传入年月日实例化时间
            var dtm = new DateTime(int.Parse(year), int.Parse(month), int.Parse(day));
            // 获得传入年月日的地支
            var sexagenaryYear = chineseCalender.GetSexagenaryYear(dtm);
            // 截取生肖
            var yearOfBirth = YEAR_TREE.Substring(chineseCalender.GetTerrestrialBranch(sexagenaryYear) - 1, 1);

            return yearOfBirth;
        }
 /// <summary>
 /// 返回生肖
 /// </summary>
 /// <param name="datetime">公历日期</param>
 /// <returns></returns>
 public static string GetShengXiao(this ChineseLunisolarCalendar calendar, DateTime datetime)
 {
     return(_shengxiao[calendar.GetTerrestrialBranch(calendar.GetSexagenaryYear(datetime)) - 1]);
 }