在51aspx收集的农历日期类
生活随笔
收集整理的這篇文章主要介紹了
在51aspx收集的农历日期类
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
using System;
using System.Globalization;//
namespace ChinaDate
{
????///<summary>
????/// 顯示今天農歷類
????///</summary>
????public class CNDate
????{
????????private DateTime m_Date; //今天的日期
????????private readonly int cny; //農歷的年月日
????????private int cnm; //農歷的年月日
????????private readonly int cnd; //農歷的年月日
????????private readonly int icnm; //農歷閏月
????????///<summary>
????????/// 顯示日期構造函數
????????///</summary>
????????public CNDate()
????????{
????????????m_Date = DateTime.Today;
????????????ChineseLunisolarCalendar cnCalendar = new ChineseLunisolarCalendar();
????????????cny = cnCalendar.GetSexagenaryYear(m_Date);
????????????cnm = cnCalendar.GetMonth(m_Date);
????????????cnd = cnCalendar.GetDayOfMonth(m_Date);
????????????icnm = cnCalendar.GetLeapMonth(cnCalendar.GetYear(m_Date));
????????}
????????///<summary>
????????/// 返回格式化的公歷顯示
????????///</summary>
????????///<returns>格式如:2008年05月14日</returns>
????????public string GetDate()
????????{
????????????int y = m_Date.Year;
????????????int m = m_Date.Month;
????????????int d = m_Date.Day;
????????????return String.Format("{0}年{1:00}月{2:00}日", y, m, d);
????????}
????????///<summary>
????????/// 返回格式化的星期顯示
????????///</summary>
????????///<returns>格式如:星期日</returns>
????????public string GetWeek()
????????{
????????????string ws = "星期";
????????????int w = Convert.ToInt32(m_Date.DayOfWeek);
????????????ws = ws + "日一二三四五六".Substring(w, 1);
????????????return ws;
????????}
????????///<summary>
????????/// 返回格式化的農歷顯示
????????///</summary>
????????///<returns>格式如:戊子(鼠)年潤四月廿三</returns>
?& nbsp;??????public string GetCNDate()
????????{
????????????string txcns = "";
????????????const string szText1 = "癸甲乙丙丁戊己庚辛壬";
????????????const string szText2 = "亥子丑寅卯辰巳午未申酉戌";
????????????const string szText3 = "豬鼠牛虎免龍蛇馬羊猴雞狗";
????????????int tn = cny % 10; //天干
????????????int dn = cny % 12;??//地支
????????????txcns += szText1.Substring(tn, 1);
????????????txcns += szText2.Substring(dn, 1);
????????????txcns += "("+ szText3.Substring(dn, 1) +")年";
????????????//格式化月份顯示
????????????string[] cnMonth ={"","正月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月", "十二月" };
????????????if (icnm > 0)
????????????{
????????????????for (int i = icnm+1; i <cnMonth.Length; i++)
????????????????????cnMonth = cnMonth;
????????????????cnMonth[icnm] = "閏" + cnMonth[icnm-1];
????????????}
????????????txcns += cnMonth[cnm];
????????????string[] cnDay ={ "", "初一", "初二", "初三", "初四", "初五", "初六", "初七"
, "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五", "十六"
, "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五"
, "廿六", "廿七", "廿八", "廿九", "三十" };
????????????txcns += cnDay[cnd];
????????????return txcns;
????????}
????}
}
測試效果如上圖所示.
using System.Globalization;//
namespace ChinaDate
{
????///<summary>
????/// 顯示今天農歷類
????///</summary>
????public class CNDate
????{
????????private DateTime m_Date; //今天的日期
????????private readonly int cny; //農歷的年月日
????????private int cnm; //農歷的年月日
????????private readonly int cnd; //農歷的年月日
????????private readonly int icnm; //農歷閏月
????????///<summary>
????????/// 顯示日期構造函數
????????///</summary>
????????public CNDate()
????????{
????????????m_Date = DateTime.Today;
????????????ChineseLunisolarCalendar cnCalendar = new ChineseLunisolarCalendar();
????????????cny = cnCalendar.GetSexagenaryYear(m_Date);
????????????cnm = cnCalendar.GetMonth(m_Date);
????????????cnd = cnCalendar.GetDayOfMonth(m_Date);
????????????icnm = cnCalendar.GetLeapMonth(cnCalendar.GetYear(m_Date));
????????}
????????///<summary>
????????/// 返回格式化的公歷顯示
????????///</summary>
????????///<returns>格式如:2008年05月14日</returns>
????????public string GetDate()
????????{
????????????int y = m_Date.Year;
????????????int m = m_Date.Month;
????????????int d = m_Date.Day;
????????????return String.Format("{0}年{1:00}月{2:00}日", y, m, d);
????????}
????????///<summary>
????????/// 返回格式化的星期顯示
????????///</summary>
????????///<returns>格式如:星期日</returns>
????????public string GetWeek()
????????{
????????????string ws = "星期";
????????????int w = Convert.ToInt32(m_Date.DayOfWeek);
????????????ws = ws + "日一二三四五六".Substring(w, 1);
????????????return ws;
????????}
????????///<summary>
????????/// 返回格式化的農歷顯示
????????///</summary>
????????///<returns>格式如:戊子(鼠)年潤四月廿三</returns>
?& nbsp;??????public string GetCNDate()
????????{
????????????string txcns = "";
????????????const string szText1 = "癸甲乙丙丁戊己庚辛壬";
????????????const string szText2 = "亥子丑寅卯辰巳午未申酉戌";
????????????const string szText3 = "豬鼠牛虎免龍蛇馬羊猴雞狗";
????????????int tn = cny % 10; //天干
????????????int dn = cny % 12;??//地支
????????????txcns += szText1.Substring(tn, 1);
????????????txcns += szText2.Substring(dn, 1);
????????????txcns += "("+ szText3.Substring(dn, 1) +")年";
????????????//格式化月份顯示
????????????string[] cnMonth ={"","正月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月", "十二月" };
????????????if (icnm > 0)
????????????{
????????????????for (int i = icnm+1; i <cnMonth.Length; i++)
????????????????????cnMonth = cnMonth;
????????????????cnMonth[icnm] = "閏" + cnMonth[icnm-1];
????????????}
????????????txcns += cnMonth[cnm];
????????????string[] cnDay ={ "", "初一", "初二", "初三", "初四", "初五", "初六", "初七"
, "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五", "十六"
, "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五"
, "廿六", "廿七", "廿八", "廿九", "三十" };
????????????txcns += cnDay[cnd];
????????????return txcns;
????????}
????}
}
測試效果如上圖所示.
轉載于:https://www.cnblogs.com/crid/archive/2010/11/28/5172700.html
總結
以上是生活随笔為你收集整理的在51aspx收集的农历日期类的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 日子过得真快,转眼就工作了4个月了
- 下一篇: linux 每日学一点《Linux架设代