• 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;
            }
  • 相关阅读:
    汉罗塔问题
    有进度条圆周率计算
    turtle库笔记
    OwnCloud建立属于自己私有的云存储网盘
    HTTP 常见请求状态码
    虚拟机部署Kubernetes集群
    常用文件头(16进制)
    配置LAMP环境
    Linux系统日志
    Java的socket通信与操作系统的SocketAPI关系探究
  • 原文地址:https://www.cnblogs.com/ymtianyu/p/5591480.html
Copyright © 2020-2023  润新知