• 农历查询


    1using System;
    2using System.Collections.Generic;
    3using System.Text;
    4using System.Globalization;
    5
    6namespace chinese.D0086.Date
    7{
    8    public class chinaDate
    9    {
    10        public string cDate()
    11        {
    12            ChineseLunisolarCalendar l = new ChineseLunisolarCalendar();
    13            DateTime dt = DateTime.Today; //转换当日的日期
    14            //dt = new DateTime(2006, 1,29);//农历2006年大年初一(测试用),也可指定日期转换
    15            string[] aMonth ={"","正月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "腊月", "腊月" };
    16            //a10表示日期的十位!
    17            string[] a10 ={ "", "", "廿", "" };
    18            string[] aDigi ={ "", "", "", "", "", "", "", "", "", "" };
    19            string sYear = "", sYearArab = "", sMonth = "", sDay = "", sDay10 = "", sDay1 = "", sLuniSolarDate = "";
    20            int iYear, iMonth, iDay;
    21            iYear = l.GetYear(dt);
    22            iMonth = l.GetMonth(dt);
    23            iDay = l.GetDayOfMonth(dt);
    24
    25            //Format Year
    26            sYearArab = iYear.ToString();
    27            for (int i = 0; i < sYearArab.Length; i++)
    28            {
    29                sYear += aDigi[Convert.ToInt16(sYearArab.Substring(i, 1))];
    30            }
    31
    32            //Format Month
    33            int iLeapMonth = l.GetLeapMonth(iYear); //获取闰月
    34
    35/*闰月可以出现在一年的任何月份之后。例如,GetMonth 方法返回一个介于 1 到 13 之间的数字来表示与指定日期关联的月份。如果在一年的八月和九月之间有一个闰月,则 GetMonth 方法为八月返回 8,为闰八月返回 9,为九月返回 10。*/  
    36        
    37            if (iLeapMonth > 0 && iMonth<=iLeapMonth)
    38            {
    39                //for (int i = iLeapMonth + 1; i < 13; i++) aMonth = aMonth[i - 1];
    40                aMonth[iLeapMonth] = "" + aMonth[iLeapMonth-1];
    41                sMonth = aMonth[l.GetMonth(dt)];
    42            }
    43            else if (iLeapMonth > 0 && iMonth > iLeapMonth)
    44            {
    45                sMonth = aMonth[l.GetMonth(dt) - 1];
    46            }
    47            else
    48            {
    49                sMonth = aMonth[l.GetMonth(dt)];
    50            }
    51
    52
    53            //Format Day
    54            sDay10 = a10[iDay / 10];
    55            sDay1 = aDigi[(iDay % 10)];
    56            sDay = sDay10 + sDay1;
    57
    58            if (iDay == 10) sDay = "初十";
    59            if (iDay == 20) sDay = "二十";
    60            if (iDay == 30) sDay = "三十";
    61
    62            //Format Lunar Date
    63            //sLuniSolarDate = dt.Year+"年"+dt.Month+"月"+dt.Day+"日 "+Weeks(dt.DayOfWeek.ToString())+" 农历" + sYear + "年" + sMonth + sDay;
    64            sLuniSolarDate = dt.Year + "" + dt.Month + "" + dt.Day + "" + Weeks(dt.DayOfWeek.ToString()) + " 农历" + sMonth + sDay;
    65            return sLuniSolarDate;
    66           
    67        }
    68        private string Weeks(string Weeken)
    69        {
    70            switch (Weeken)
    71            {
    72                case "Monday":
    73                    return "星期一";
    74                    break;
    75                case "Tuesday":
    76                    return "星期二";
    77                    break;
    78                case "Wednesday":
    79                    return "星期三";
    80                    break;
    81                case "Thursday":
    82                    return "星期四";
    83                    break;
    84                case "Friday":
    85                    return "星期五";
    86                    break;
    87                case "Saturday":
    88                    return "星期六";
    89                    break;
    90                case "Sunday":
    91                    return "星期日";
    92                    break;
    93                default:
    94                    return " ";
    95            }
    96            
    97        }
    98    }
    99}
  • 相关阅读:
    项目经验分享(上)
    socket.io实现在线群聊
    socket.io中文文档
    常用的Sublime Text插件及安装方法
    常用的Atom插件
    atom及其插件activate-power-mode下载安装
    jeesite快速开发平台
    js权威指南
    hexSHA1散列加密解密(不可逆)
    腾讯云企业邮箱
  • 原文地址:https://www.cnblogs.com/haoqi/p/3384693.html
Copyright © 2020-2023  润新知