public void TestDay()
        {
            TaiwanLunisolarCalendar tlc = new TaiwanLunisolarCalendar();

            int year = tlc.GetYear(DateTime.Now);
            int month = tlc.GetMonth(DateTime.Now);
            int day = tlc.GetDayOfMonth(DateTime.Now);

            string aa = string.Format("{0}/{1}/{2}", year, month, day);
            Console.WriteLine("day = " + aa);

            DateTime date2 = tlc.ToDateTime(year, month, day, 0, 0, 0, 0);
            Console.WriteLine("day2 = " + date2.ToShortDateString());
        }
Exemple #2
0
        /// <summary>
        /// 取得今天的日期種類
        /// </summary>
        /// <returns></returns>
        public static DayKind GetWhatDayIsToday(DateTime Today)
        {
            TaiwanLunisolarCalendar TLC = new TaiwanLunisolarCalendar();
            //農曆日期
            DateTime LunaDate = new DateTime(TLC.GetYear(Today)
                                            , TLC.GetMonth(Today)
                                            , TLC.GetDayOfMonth(Today));
            //西元日期
            DateTime DCDate = Today;

            if (!TLC.IsLeapMonth(LunaDate.Year, LunaDate.Month))//處理農曆閏月
            {
                switch (LunaDate.Month)
                {
                    case 1:
                        //農曆一月

                        switch (LunaDate.Day)
                        {
                            //初一到初五
                            case 1:
                            case 2:
                            case 3:
                            case 4:
                            case 5:
                                return DayKind.ChineseNewYear;
                        }
                        break;
                    case 5:
                        //五月初五,端午節
                        if (LunaDate.Day == 5)
                            return DayKind.ChineseDragonBoatFestival;
                        break;
                    case 7:
                        //七夕情人節
                        if (LunaDate.Day == 7)
                            return DayKind.ChineseValentine;
                        break;
                    case 8:
                        //八月十五中秋節
                        if (LunaDate.Day == 15)
                            return DayKind.ChineseLunaDay;
                        break;
                    case 12:
                        //除夕
                        if (LunaDate.DayOfYear == (DateTime.IsLeapYear(DCDate.Year) ? 366 : 365))
                            return DayKind.ChineseNewYearEve;
                        break;
                }
            }
            switch (DCDate.Month)
            {
                case 2:
                    switch (DCDate.Day)
                    {
                        case 14:
                            return DayKind.ValentineDay;
                        case 28:
                            return DayKind.Taiwan228;
                    }
                    break;
                case 12:
                    if (DCDate.Day == 24)
                        return DayKind.Xmas;
                    break;
            }
            switch (DCDate.DayOfWeek)
            {
                case DayOfWeek.Saturday:
                case DayOfWeek.Sunday:
                    return DayKind.WeekVocation;
            }
            return DayKind.WorkDay;
        }