• C#根据当前日期获取星期和阴历日期


    private string GetWeek(int dayOfWeek)
            {
                string returnWeek = "";
                switch (dayOfWeek)
                {
                    case 1:
                        returnWeek = "星期一";
                        break;
                    case 2:
                        returnWeek = "星期二";
                        break;
                    case 3:
                        returnWeek = "星期三";
                        break;
                    case 4:
                        returnWeek = "星期四";
                        break;
                    case 5:
                        returnWeek = "星期五";
                        break;
                    case 6:
                        returnWeek = "星期六";
                        break;
                    case 0:
                        returnWeek = "星期日";
                        break;
                }
                return returnWeek;
            }
    private string GetChineseDateTime(DateTime datetime)
            {
                ChineseLunisolarCalendar ChinaData = new ChineseLunisolarCalendar();
    
                int lyear = ChinaData.GetYear(datetime);
                int lmonth = ChinaData.GetMonth(datetime);
                int lday = ChinaData.GetDayOfMonth(datetime);
    
                //获取闰月, 0 则表示没有闰月
                int leapMonth = ChinaData.GetLeapMonth(lyear);
                bool isleap = false;
                if (leapMonth > 0)
                {
                    if (leapMonth == lmonth)
                    {
                        //闰月
                        isleap = true;
                        lmonth--;
                    }
                    else if (lmonth > leapMonth)
                    {
                        lmonth--;
                    }
                }
    
                //十天干
                string[] tiangan = { "", "", "", "", "", "", "", "", "", "" };
                //十二地支
                string[] dizhi = { "", "", "", "", "", "", "", "", "", "", "", "" };
                //十二生肖
                string[] shengxiao = { "", "", "", "", "", "", "", "", "", "", "", "" };
    
                string ChinaYear = "";
                if (lyear > 3)
                {
                    int tgIndex = (lyear - 4) % 10;
                    int dzIndex = (lyear - 4) % 12;
    
                    ChinaYear = string.Concat(tiangan[tgIndex], dizhi[dzIndex], "[", shengxiao[dzIndex], "]");
    
                }
    
                string[] months = { "", "", "", "", "", "", "", "", "", "", "十一", "十二(腊)" };
    
                string ChinaMonth = "";
                if (lmonth < 13 && lmonth > 0)
                {
                    ChinaMonth = months[lmonth - 1];
                }
    
                string[] days1 = { "", "", "廿", "" };
                string[] days = { "", "", "", "", "", "", "", "", "", "" };
    
                string ChinaDay = "";
                if (lday > 0 && lday < 32)
                {
                    if (lday != 20 && lday != 30)
                    {
                        ChinaDay = string.Concat(days1[(lday - 1) / 10], days[(lday - 1) % 10]);
                    }
                    else
                    {
                        ChinaDay = string.Concat(days[(lday - 1) / 10], days1[1]);
                    }
                }
    
                return string.Concat(ChinaYear, "", isleap ? "" : string.Empty, "
    农历 ", ChinaMonth, "", ChinaDay);
                //return "农历 " + ChinaMonth + "月" + ChinaDay;
            }
  • 相关阅读:
    NOIP模拟 回文序列
    NOIP模拟 最佳序列
    BZOJ 2783 树
    BZOJ 3631 松鼠的新家
    洛谷 6道简单图论
    NOI模拟 颜色
    NOIP模拟 Game
    BZOJ1415 聪聪与可可
    Codeforces Round #443 (Div. 2) C: Short Program
    20171028洛谷NOIP模拟
  • 原文地址:https://www.cnblogs.com/ymtianyu/p/5591480.html
Copyright © 2020-2023  润新知