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; }