ChineseCalendar类[转]
生活随笔
收集整理的這篇文章主要介紹了
ChineseCalendar类[转]
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
????///<summary>
????///Title:?ChineseCalendar類
????///Description:?中文日期工具類
????///@author?萬靈杰[作者]
????///@version?1.0.0.0
????///@date?2009年7月30日
????///@modify?
????///@date?
????///?</summary>
????public?class?ChineseCalendar
????{
????????private?static?readonly?string[]?Animals?=?new?string[]?{?"鼠",?"牛",?"虎",?"兔",?"龍",?"蛇",?"馬",?"羊",?"猴",?"雞",?"狗",?"豬"?};
????????private?static?readonly?string[]?arrCnNames?=?new?string[]?{?"日",?"一",?"二",?"三",?"四",?"五",?"六"?};
????????private?static?ChineseLunisolarCalendar?calendar?=?new?ChineseLunisolarCalendar();
????????private?const?string?CelestialStem?=?"甲乙丙丁戊己庚辛壬癸";
????????private?static?readonly?string[]?ChineseDayName?=?new?string[]?{?
????????????"初一",?"初二",?"初三",?"初四",?"初五",?"初六",?"初七",?"初八",?"初九",?"初十",?"十一",?"十二",?"十三",?"十四",?"十五",?"十六",?
????????????"十七",?"十八",?"十九",?"二十",?"廿一",?"廿二",?"廿三",?"廿四",?"廿五",?"廿六",?"廿七",?"廿八",?"廿九",?"三十"
?????????};
????????private?static?readonly?string[]?ChineseMonthName?=?new?string[]?{?"正",?"二",?"三",?"四",?"五",?"六",?"七",?"八",?"九",?"十",?"十一",?"十二"?};
????????private?static?string?ChineseNumber?=?"〇一二三四五六七八九";
????????private?const?string?TerrestrialBranch?=?"子丑寅卯辰巳午未申酉戌亥";
????????public?static?string?Now
????????{
????????????get
????????????{
????????????????return?GetChineseCalendar(DateTime.Now);
????????????}
????????}
????????public?static?string?GetAnimals(DateTime?time)
????????{
????????????return?Animals[(calendar.GetYear(time)?-?4)?%?12];
????????}
????????public?static?string?GetChineseCalendar(DateTime?time)
????????{
????????????return?string.Format("{0}年{1}月{2}",?GetStemBranch(time),?GetMonth(time),?GetDay(time));
????????}
????????public?static?string?GetDay(DateTime?time)
????????{
????????????return?ChineseDayName[calendar.GetDayOfMonth(time)?-?1];
????????}
????????public?static?string?GetMonth(DateTime?time)
????????{
????????????int?month?=?calendar.GetMonth(time);
????????????int?year?=?calendar.GetYear(time);
????????????int?num3?=?0;
????????????for?(int?i?=?3;?i?<=?month;?i++)
????????????{
????????????????if?(calendar.IsLeapMonth(year,?i))
????????????????{
????????????????????num3?=?i;
????????????????????break;
????????????????}
????????????}
????????????if?(num3?>?0)
????????????{
????????????????month--;
????????????}
????????????return?(((num3?==?(month?+?1))???"閏"?:?"")?+?ChineseMonthName[month?-?1]);
????????}
????????public?static?string?GetStemBranch(DateTime?time)
????????{
????????????int?sexagenaryYear?=?calendar.GetSexagenaryYear(time);
????????????int?startIndex?=?(sexagenaryYear?%?12)?-?1;
????????????if?(startIndex?>?11)
????????????{
????????????????startIndex?=?0;
????????????}
????????????if?(startIndex?<?0)
????????????{
????????????????startIndex?=?11;
????????????}
????????????int?num3?=?(sexagenaryYear?%?10)?-?1;
????????????if?(num3?>?9)
????????????{
????????????????num3?=?0;
????????????}
????????????if?(num3?<?0)
????????????{
????????????????num3?=?9;
????????????}
????????????return?("甲乙丙丁戊己庚辛壬癸".Substring(num3,?1)?+?"子丑寅卯辰巳午未申酉戌亥".Substring(startIndex,?1));
????????}
????????public?static?string?GetWeekDayName(DateTime?time)
????????{
????????????return?("星期"?+?arrCnNames[(int)time.DayOfWeek]);
????????}
????????public?static?string?GetYear(DateTime?time)
????????{
????????????StringBuilder?builder?=?new?StringBuilder();
????????????int?year?=?calendar.GetYear(time);
????????????do
????????????{
????????????????int?num2?=?year?%?10;
????????????????builder.Insert(0,?ChineseNumber[num2]);
????????????????year?/=?10;
????????????}
????????????while?(year?>?0);
????????????return?builder.ToString();
????????}
????}
????///Title:?ChineseCalendar類
????///Description:?中文日期工具類
????///@author?萬靈杰[作者]
????///@version?1.0.0.0
????///@date?2009年7月30日
????///@modify?
????///@date?
????///?</summary>
????public?class?ChineseCalendar
????{
????????private?static?readonly?string[]?Animals?=?new?string[]?{?"鼠",?"牛",?"虎",?"兔",?"龍",?"蛇",?"馬",?"羊",?"猴",?"雞",?"狗",?"豬"?};
????????private?static?readonly?string[]?arrCnNames?=?new?string[]?{?"日",?"一",?"二",?"三",?"四",?"五",?"六"?};
????????private?static?ChineseLunisolarCalendar?calendar?=?new?ChineseLunisolarCalendar();
????????private?const?string?CelestialStem?=?"甲乙丙丁戊己庚辛壬癸";
????????private?static?readonly?string[]?ChineseDayName?=?new?string[]?{?
????????????"初一",?"初二",?"初三",?"初四",?"初五",?"初六",?"初七",?"初八",?"初九",?"初十",?"十一",?"十二",?"十三",?"十四",?"十五",?"十六",?
????????????"十七",?"十八",?"十九",?"二十",?"廿一",?"廿二",?"廿三",?"廿四",?"廿五",?"廿六",?"廿七",?"廿八",?"廿九",?"三十"
?????????};
????????private?static?readonly?string[]?ChineseMonthName?=?new?string[]?{?"正",?"二",?"三",?"四",?"五",?"六",?"七",?"八",?"九",?"十",?"十一",?"十二"?};
????????private?static?string?ChineseNumber?=?"〇一二三四五六七八九";
????????private?const?string?TerrestrialBranch?=?"子丑寅卯辰巳午未申酉戌亥";
????????public?static?string?Now
????????{
????????????get
????????????{
????????????????return?GetChineseCalendar(DateTime.Now);
????????????}
????????}
????????public?static?string?GetAnimals(DateTime?time)
????????{
????????????return?Animals[(calendar.GetYear(time)?-?4)?%?12];
????????}
????????public?static?string?GetChineseCalendar(DateTime?time)
????????{
????????????return?string.Format("{0}年{1}月{2}",?GetStemBranch(time),?GetMonth(time),?GetDay(time));
????????}
????????public?static?string?GetDay(DateTime?time)
????????{
????????????return?ChineseDayName[calendar.GetDayOfMonth(time)?-?1];
????????}
????????public?static?string?GetMonth(DateTime?time)
????????{
????????????int?month?=?calendar.GetMonth(time);
????????????int?year?=?calendar.GetYear(time);
????????????int?num3?=?0;
????????????for?(int?i?=?3;?i?<=?month;?i++)
????????????{
????????????????if?(calendar.IsLeapMonth(year,?i))
????????????????{
????????????????????num3?=?i;
????????????????????break;
????????????????}
????????????}
????????????if?(num3?>?0)
????????????{
????????????????month--;
????????????}
????????????return?(((num3?==?(month?+?1))???"閏"?:?"")?+?ChineseMonthName[month?-?1]);
????????}
????????public?static?string?GetStemBranch(DateTime?time)
????????{
????????????int?sexagenaryYear?=?calendar.GetSexagenaryYear(time);
????????????int?startIndex?=?(sexagenaryYear?%?12)?-?1;
????????????if?(startIndex?>?11)
????????????{
????????????????startIndex?=?0;
????????????}
????????????if?(startIndex?<?0)
????????????{
????????????????startIndex?=?11;
????????????}
????????????int?num3?=?(sexagenaryYear?%?10)?-?1;
????????????if?(num3?>?9)
????????????{
????????????????num3?=?0;
????????????}
????????????if?(num3?<?0)
????????????{
????????????????num3?=?9;
????????????}
????????????return?("甲乙丙丁戊己庚辛壬癸".Substring(num3,?1)?+?"子丑寅卯辰巳午未申酉戌亥".Substring(startIndex,?1));
????????}
????????public?static?string?GetWeekDayName(DateTime?time)
????????{
????????????return?("星期"?+?arrCnNames[(int)time.DayOfWeek]);
????????}
????????public?static?string?GetYear(DateTime?time)
????????{
????????????StringBuilder?builder?=?new?StringBuilder();
????????????int?year?=?calendar.GetYear(time);
????????????do
????????????{
????????????????int?num2?=?year?%?10;
????????????????builder.Insert(0,?ChineseNumber[num2]);
????????????????year?/=?10;
????????????}
????????????while?(year?>?0);
????????????return?builder.ToString();
????????}
????}
轉載于:https://www.cnblogs.com/chenqingwei/archive/2010/06/09/1754448.html
總結
以上是生活随笔為你收集整理的ChineseCalendar类[转]的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 求把下面这张图片的字体颜色变得更清楚,跟
- 下一篇: 独角天使值多少?