zoukankan      html  css  js  c++  java
  • 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;
            }
  • 相关阅读:
    屏蔽Alt+Enter、Ctrl+Alt+Del、Ctrl+Esc等功能键(Windows 98/Me)
    获取本月第一天和最后一天的最简单的写法
    PHP程序员的优化调试技术和技巧
    Windows关机函数ExitWindowsEx使用大全(适用Windows所有操作平台)
    屏蔽Alt+Enter、Ctrl+Alt+Del、Ctrl+Esc等功能键(Windows 98/Me)
    PHP程序员的优化调试技术和技巧
    Ajax,再生还是幻灭好文推荐
    RAID 分类
    Ajax,再生还是幻灭好文推荐
    Windows关机函数ExitWindowsEx使用大全(适用Windows所有操作平台)
  • 原文地址:https://www.cnblogs.com/ymtianyu/p/5591480.html
Copyright © 2011-2022 走看看