万年日历(C语言)

发布于:2022-12-31 ⋅ 阅读:(336) ⋅ 点赞:(0)

C Language 万年历程序----(1840~2110)年

##声明:此程序并非本人全原创,已修改其中少数内容,仅供小白参考,大佬者若言论,来吧,用点力——后续本人将更新此万年历添加更有丰富的内容,先让此源码再飞一会儿(暂时没空,腾不出手),各位使劲消化下。源例请参考《C语言项目开发全程实录》第二版。但这书是个外包公司编撰,内容很dog,主要体现为在大多项目程序主要关键算法处一概而过,要么直接跳过去。资源视频讲解完全照着注释一句句念。所以小白看的一头雾水,老白看的似懂非懂,大佬:什么鬼(仅个人愚见,望海涵)但大多事实。
写此文章原因:一,因书内所编写的程序很经典,仅能在书内指定的IDE(DEV-C++)下运行。
二,本人查询了关于本人目前已知销售此书的原址出反馈,评论。发现不少萌新直接拿书内源程序一字不差照搬(您仔细审阅下那代码块顺序,逻辑运行,往前翻看下业务流程图,就不会猛抄了),导致BUG满天飞的现象(此书页面内大多只提供80%源码并附于解说,并非完整程序)——虽然书内提供了完整源码资源下载网址,但若想在其它编译器上正确运行,依旧最好别照搬,还是那句话“请在本书指定IDE下运行”。所以,本人如今把修改后可以在常用的VS2015~2019系列下运行的发布下。本人常用PC.VS Enterprise 2017x64。VS2017加载修改后C语言部分效果展示(8个功能块较多不再展示)如下:
请添加图片描述请添加图片描述
主函数全部源码如下

#include"Calendar.h"

int main()
{
	system("color f0");//控制台背景显示为白色。
	int mode = 0;
	int year, month, day, dMn, days;
	int error_times = 0;
	LUNARDATE lunar_date;
	LONGTIME It;
	while (error_times < 5) {
		year = -1, month = -1, dMn = -1, days = 9025910;
		printf("\t\t\t C语言万年历(1840~2110)\n\n");
		It = GetCurTime();
		hOut = GetStdHandle(STD_OUTPUT_HANDLE);//获取控制台输出句柄
		SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);//更改文字颜色,为红色
		printf("\t\t\t   %d-%d-%d %02d:%02d:%02d %s\r\n\n", It.wYear, It.wMonth, It.wDay, It.wHour, It.wMinute, It.wSecond, Week[It.wDayOfWeek]);//输出年,月,日,时,分,秒,周
		SetConsoleTextAttribute(hOut, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);//返回文字颜色,为蓝色。色彩设置根据三原色混色标准设定,例如:黑色+白色=灰,红+绿=黄,蓝+红=紫 等......
		SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);
		printf("\t\t\t      ★");
		SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED |
			FOREGROUND_BLUE);
		printf("★");
		SetConsoleTextAttribute(hOut, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
		printf("功能选择:");
		SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE |
			FOREGROUND_GREEN);
		printf("★");
		SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);
		printf("★         \n\n");
		SetConsoleTextAttribute(hOut, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
		//打印主界面菜单选项
		printf("\t\t-------------------------------------------------\n");
		printf("\t\t|\t*  1、农历  \t\t\t\t|\n\t\t|\t\t\t\t\t\t|\n\t\t|\t*  "
			"2、公历  \t\t\t\t|\n\t\t|\t\t\t\t\t\t|\n\t\t|\t*  "
			"3、月历  \t\t\t\t|\n\t\t|\t\t\t\t\t\t|\n\t\t|\t*  "
			"4、某天距今天的天数  \t\t|\n\t\t|\t\t\t\t\t\t|\n\t\t|\t*  "
			"5、距今天相应天数的日期   \t\t|\n\t\t|\t\t\t\t\t\t|\n\t\t|\t*  "
			"6、任意两天之间的天数差   \t\t|\n\t\t|\t\t\t\t\t\t|\n\t\t|\t*  "
			"7、二十四节气  \t\t\t|\n\t\t|\t\t\t\t\t\t|\n\t\t|\t*  "
			"8、节日  \t\t\t\t|\n");
		printf("\t\t-------------------------------------------------\n");
		printf("\t\t你的输入: ");
		scanf_s("%d", &mode);//输入功能选择序号1,2,3,4,5,6,7,8
		system("cls");//每次选择功能后,刷新菜单
	It = GetCurTime();//无论选择哪项,将会一直显示当前时间
	printf("\t\t当前时间:%d-%d-%d %02d:%02d:%02d %s\r\n\r\n", It.wYear, It.wMonth, It.wDay, It.wHour, It.wMinute, It.wSecond, Week[It.wDayOfWeek]);

	//万年历功能响应模板
	switch (mode) {
	case 1:
		printf("农历查询:\n\n");
		printf("请输入要查询的公历日期(输入格式为:年 月 日):Year Month Day>");
		while (1)
		{
			scanf_s("%d %d %d", &year, &month, &day);//输入年,月,日
			if (year <= start_year || year > end_year || month < 1 || month>12 || day < 1 || day>31)
			{
				error_times++;
				printf("您输入的日期有误,请重新输入(错误%d 次/5 次): Year Month Day>", error_times);
				if (error_times >= 5)
				{
					printf("\r\n错误次数已达上限,请按任意键退出程序。");
					system("pause>nul");//系统退出按键映射
					return 1;
				}
			}
			else
			{
				dMn = GetDaysOfMonth(year, month, false, false);
				if (day > dMn)
				{
					error_times++;
					printf("当前月份只有%d 天。请重新输入(错误%d 次/5 次):Year Month Day>", dMn, error_times);
					if (error_times >= 5)
					{
						printf("\r\n错误次数已达上限,请按任意键退出程序。");
						system("pause>nul");
						return 1;
					}
				}
				else
				{
					break;
				}
			}
			LONGTIME It;
			double SoTer1, SoTer2;//24节气临时变量
			int index_Solterms = 0;//24节气序号
			int dM0 = CriterionDay(year, month, 1);
			int row = 0, line = 0;//行,列
			row = year - start_year;
			for (index_Solterms = (month - 1) * 2; index_Solterms < 24; index_Solterms++)
			{
				SoTer1 = SolTerms[row * 24 + index_Solterms];
				SoTer2 = SolTerms[row * 24 + index_Solterms + 1];
				if (int2(SoTer1 + 0.5) <= (dM0 + 14) && int2(SoTer2 + 0.5) > (dM0 + 14))
				{
					break;
				}
			}
			//显示当月节气
			It = GetDate(SoTer1);
			hOut = GetStdHandle(STD_OUTPUT_HANDLE);
			SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);//更改文字颜色,为蓝色
			printf("\n\t%s: %d-%d-%d %02d:%02d:%02d  ", Solterms[(index_Solterms) % 24], It.wYear, It.wMonth, It.wDay, It.wHour, It.wMinute, It.wSecond);
			It = GetDate(SoTer2);//显示下一个节气,并计算输出当月节气于下一个节气之间的时间差
			printf("%s: %d-%d-%d %02d:%02d:%02d\r\n\r\n", Solterms[(index_Solterms + 1) % 24], It.wYear, It.wMonth, It.wDay, It.wHour,
				It.wMinute, It.wSecond);
			SetConsoleTextAttribute(hOut, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
		}
		ShowCalendar(year, month, day);
		DateRefer(year, month, day, false);
		break;
	case 2:
		printf("公历查询: \r\n\r\n");
		printf("请输入农历日期(如1949年十月一日则输入: 1949 10 1,)(范围:1840~2110)\nYear Month Day>");
		while (1)
		{
			scanf_s("%d %d %d", &year, &month, &day);
			if (year <= start_year || year > end_year || month < 1 || month>12 || day < 1 || day>30)
			{
				error_times++;//错误次数累计
				printf("您输入的日期有误,请重新输入(错误%d 次/5 次):Year Month Day>", error_times);
				if (error_times >= 5)
				{
					printf("\r\n错误次数已达上限,请按任意键退出程序。");
					system("pause>nul");
					return 1;
				}
			}
			else
			{
				lunar_date.iYear = year;
				lunar_date.wMonth = month;
				lunar_date.wDay = day;
				lunar_date.blsLeap = false;
				if (GetGre(lunar_date) != 0)
				{
					error_times++;
					//错误计数大于等于5次,显示警告信息
					if (error_times >= 5)
					{
						printf("\r\n错误次数已达上限,请按任意键退出程序。");
						system("pause>nul");
						return 1;
					}
				}
				else
				{
					break;
				}
			}
		}
		printf("\r\n");
		break;
	case 3:
		printf("月历显示:\r\n\r\n");
		printf("请输入要查询的公历年月(1840~2110):Year Month Day>");
		while (1)
		{
			scanf_s("%d %d %d", &year, &month, &day);
			if (year <= start_year || year > end_year || month < 1 || month>12)
			{
				error_times++;
				printf("您输入的年月有误,请重新输入(错误%d 次/5 次)。Year Month", error_times);
				if (error_times >= 5)
				{
					printf("\r\n错误次数已达上限,请按任意键退出程序。");
					system("pause>nul");
					return 1;
				}
			}
			else
			{
				break;
			}
		}
		ShowCalendar(year, month, day);//打印当月月历
		break;
	case 4:
		printf("查询某天距今天的天数:\r\n\r\n");
		printf("请输入日期:Year Month Day>");
		while (1)
		{
			scanf_s("%d %d %d", &year, &month, &day);
			if (year <= start_year || year > end_year || month > 12 || month < 1 || day > 31 || day < 1)
			{
				error_times++;
				printf("您输入的日期有误,请重新输入(错误%d 次/5 次):Year Month Day>", error_times);
				if (error_times >= 5)
				{
					printf("\r\n错误次数已达上限,请按任意键退出程序。");
					system("pause>nul");
					return 1;
				}
			}
			else
			{
				dMn = GetDaysOfMonth(year, month, false, false);//获取当月实际天数
				if (day > dMn)
				{
					error_times++;
					printf("当前月份只有%d 天。请重新输入(错误%d 次/5 次):Year Month Day>", dMn, error_times);
					if (error_times >= 5)
					{
						printf("\r\n错误次数已达上限,请按任意键退出程序。");
						system("pause>nul");
						return 1;
					}
				}
				else
				{
					break;
				}
			}
		}
		dMn = CriterionDay(year, month, day);//获得当月实际天数
		It = GetCurTime();
		dMn = CriterionDay(It.wYear, It.wMonth, It.wDay);
		hOut = GetStdHandle(STD_OUTPUT_HANDLE);
		if (dMn >= 0)
		{
			SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);
			printf("%d-%d-%d", year, month, day);
			SetConsoleTextAttribute(hOut, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
			printf("比今天(");
			SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);
			printf("%d-%d-%d", It.wYear, It.wMonth, It.wDay);
			SetConsoleTextAttribute(hOut, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
			printf(") 晚【");
			SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE |
				FOREGROUND_RED);
			printf("%d", dMn);
			SetConsoleTextAttribute(hOut, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
			printf("】天\r\n\n\n\n");
		}
		else
		{
			SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);
			printf("%d-%d-%d", year, month, day);
			SetConsoleTextAttribute(hOut, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
			printf("比今天(");
			SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);
			printf("%d-%d-%d", It.wYear, It.wMonth, It.wDay);
			SetConsoleTextAttribute(hOut, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
			printf(") 早【");
			SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE |
				FOREGROUND_RED);
			printf("%d", dMn);
			SetConsoleTextAttribute(hOut, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
			printf("】天\r\n\n\n\n");
		}
		break;
	case 5:
		LONGTIME It, It2, It3;
		It = GetCurTime();
		dMn = CriterionDay(It.wYear, It.wMonth, It.wDay);
		hOut = GetStdHandle(STD_OUTPUT_HANDLE);
		printf("查询距今天相应天数的日期(请输入距今天(%d-%d-%d)的天数 范围%d~%d): ", It.wYear, It.wMonth, It.wDay, -dMn - 2451545, 6574364 - dMn);
		while (1)
		{
			scanf_s("%d", &days);
			//如果输入天数超出给定范围,会记一次错误次数。错误次数累计到5次,将退出程序。
			if (days > (6574364 - dMn) || days < (-dMn - 2451545))
			{
				if (error_times >= 5)
				{
					printf("\r\n错误次数已达上限,请按任意键退出程序。");
					system("pause>nul");
					return 1;
				}
			}
			else
			{
				break;
			}
		}
		It2 = GetDate((double)(dMn + days));
		It3 = GetDate((double)(dMn - days));
		printf("距离今天(%d-%d-%d)【 %d 】天的日期为: ", It.wYear, It.wMonth, It.wDay, days);
		SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);
		printf("\n%d-%d-%d %s", It2.wYear, It2.wMonth, It2.wDay, Week[It2.wDayOfWeek]);
		SetConsoleTextAttribute(hOut, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
		printf(" 或者为: ");
		SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);
		printf("\n%d-%d-%d %s\r\n\n\n", It3.wYear, It3.wMonth, It3.wDay, Week[It3.wDayOfWeek]);
		SetConsoleTextAttribute(hOut, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
		break;
	case 6:
		printf("查询任意两天之间的天数差: \r\n\r\n");
		printf("请输入第一个日期: Year Month Day>");
		while (1)
		{
			scanf_s("%d %d %d", &year, &month, &day);
			if (year <= start_year || year > end_year || month > 12 || month < 1 || day > 31 || day < 1)
			{
				error_times++;
				printf("您输入的日期有误,请重新输入第一个日期(错误%d 次/5 次):Year Month Day>", error_times);
				if (error_times >= 5)
				{
					printf("\r\n错误次数已达上限,请按任意键退出程序。");
					system("pause>nul");
					return 1;
				}
			}
			else
			{
				dMn = GetDaysOfMonth(year, month, false, false);//获取当月实际天数
				if (day > dMn)
				{
					error_times++;
					printf("当前月份只有%d 天。请重新输入第一个日期(错误%d 次/5 次):Year Month Day>", dMn, error_times);
					if (error_times >= 5)
					{
						printf("\r\n错误次数已达上限,请按任意键退出程序。");
						system("pause>nul");
						return 1;
					}
				}
				else
				{
					break;
				}
			}
		}
		It2.wYear = year;
		It2.wMonth = month;
		It2.wDay = day;
		printf("请输入第二个日期: Year Month Day>");
		while (1)
		{
			scanf_s("%d %d %d", &year, &month, &day);
			if (year <= start_year || year > end_year || month > 12 || month < 1 || day > 31 || day < 1)
			{
				error_times++;
				printf("您输入的日期有误,请重新输入第二个日期(错误%d 次/5 次):Year Month Day>", error_times);
				if (error_times >= 5)
				{
					printf("\r\n错误次数已达上限,请按任意键退出程序。");
					system("pause>nul");
					return 1;
				}
			}
			else
			{
				dMn = GetDaysOfMonth(year, month, false, false);//获取当月实际天数
				if (day > dMn)
				{
					error_times++;
					printf("当前月份只有%d 天。请重新输入第二个日期(错误%d 次/5 次):Year Month Day>", dMn, error_times);
					if (error_times >= 5)
					{
						printf("\r\n错误次数已达上限,请按任意键退出程序。");
						system("pause>nul");
						return 1;
					}
				}
				else
				{
					break;
				}
			}
		}
		//计算两个日期之间的差值
		days = CriterionDay(It2.wYear, It2.wMonth, It2.wDay) - CriterionDay(year, month, day);
		hOut = GetStdHandle(STD_OUTPUT_HANDLE);
		SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);
		printf("\n%d-%d-%d", It2.wYear, It2.wMonth, It2.wDay);
		SetConsoleTextAttribute(hOut, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
		printf("与");
		SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);
		printf("%d-%d-%d", year, month, day);
		SetConsoleTextAttribute(hOut, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
		printf("相差【");
		SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);
		printf("%d", abs(days));
		SetConsoleTextAttribute(hOut, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
		printf("】天。\r\n");
		break;
	case 7:
		printf("显示二十四节气:\r\n\r\n");
		printf("请输入要查询的年份(1840~2110): ");
		while (1)
		{
			scanf_s("%d", &year);
			if (year <= start_year || year > end_year)
			{
				error_times++;
				printf("您输入的年份有误,请重新输入(错误%d 次/5 次): Year>", error_times);
				if (error_times >= 5)
				{
					printf("\r\n错误次数已达上限,请按任意键退出程序。");
					system("pause>nul");
					return 1;
				}
			}
			else
			{
				break;
			}
		}
		ShowSolarTerms(year);
		break;
	case 8:
		printf("\t\t\t       显示节日\r\n\r\n");
		printf("\t\t=============================================================\n");
		printf("\n\t\t1、显示公历节日\t\t2、显示农历节日\n");
		printf("\n\t\t请选择: ");
		int choice = 0;
		scanf_s("%d", &choice);
		system("cls");
		switch (choice)
		{
		case 1:
			printf("\n\t\t\t\t 公里节日查询\n\n");
			printf("\t\t==============================================================\n");
			printf("\n");
			printf("\t\t 请输入要查询的月份: ");
			while (1)
			{
				int month = 0;
				scanf_s("%d", &month);
				if (month < 0 || month>13)
				{
					printf("\t\t输入错误,请输入正确年份(1~12):");
				}
				else
				{
					hOut = GetStdHandle(STD_OUTPUT_HANDLE);
					SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |
						FOREGROUND_RED);
					printf("\n\t\t\t\t%d月份的节日\n", month);
					SetConsoleTextAttribute(hOut, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
					Holiday(month);
					break;
				}
			}
			break;
		case 2:
			printf("\n\t\t\t\t 农历节日查询\n\n");
			printf("\t\t==============================================================\n");
			printf("\n");
			hOut = GetStdHandle(STD_OUTPUT_HANDLE);
			SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);
			printf("\n\t\t农历正月初一    春节(the Spring Festival)\n");
			printf("\n\t\t农历正月十五    元宵节(Lantern Festival)\n");
			printf("\n\t\t农历五月初五    端午节(the Dragon-Boat Festival)\n");
			printf("\n\t\t农历七月初七    七夕节(情人节)(Double-Seventh Day)\n");
			printf("\n\t\t农历八月十五    中秋节(the Mid-Autum Festival)\n");
			printf("\n\t\t农历九月初九    重阳节(the Double Ninth Festival)\n)");
			printf("\n\t\t农历腊月初八    腊八节(the laba Rice Porridge Festival)\n");
			printf("\n\t\t农历腊月二十四  传统扫房日(the Traditional House Cleaning Day)\n\n");
			SetConsoleTextAttribute(hOut, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
			break;
		default:
			error_times++;
			printf("您输入的有误,请重新输入(错误%d 次/5 次)。\r\n\r\n", error_times);
			if (error_times >= 5)
			{
				printf("\r\n错误次数已达上限,请按任意键退出程序。");
				system("pause>nul");
				return 1;
			}
			break;
		}
		break;
		}
		printf("请按任意键放回主菜单。");
		system("pause>nul");
		system("cls");
	}
	return 0;
}

/*打印一个月的月历*/
void ShowCalendar(int year, int month, int day)
{
	int dM0 = CriterionDay(year, month, 1);//公历月首天数
	int CriDay_day = dM0;//用来查询公历月首所在农历月份
	int base_days = 0;
	base_days = CriterionDay(year, month, 1);
	int dw0 = (dM0 + 142113) % 7;//月首星期
	int idw = dw0;//用于标记星期,用于第一行填充
	int dMn = GetDaysOfMonth(year, month, false, false);//获取本月总天数
	int row = 0, line = 0;
	int Lyear = 0, Lmonth = 0, Lday = 0;
	int GreCaday = 1, LunCaday = 1;
	int lunar_ndays = 0;
	const char *leap="";
	const char *MaxMini="";//大月或小月
	int dM0_lunar = 0, dM_lunar = 0;
	int cal_item = 0;
	bool isfirstline = true;
	bool fillBlanks = true;
	bool isLunarCal = false;
	double Solterms1, Solterms2;
	int Lmonth_index = 0;
	int index_Solterms = 0;
	/*LONGTIME It;*/
	row = year - start_year;//当前年份所处数据表中的行号,从开始年起算
	line = month - 1;//考虑到查询的范围,所以月份-1为初始查询序号,农历月号与公历月号最多相差2
	//查询公历月首所在农历月
	for (line; line < 15; line++)
	{
		if ((MonHead[row * 15 + line - 1] <= dM0) && (MonHead[row * 15 + line] > dM0))
		{
			break;
		}
	}
	line--;
	//查找,计算公历月序表内闰月
	if (MonOrder[row * 14 + line - 1] == MonOrder[row * 14 + line])
	{
		leap="闰";
	}
	//查找当前月份大,小月
	lunar_ndays = MonHead[row * 15 + line + 1] - MonHead[row * 15 + line];
	if (lunar_ndays == 31)
	{
		MaxMini = "大";
	}
	else if(lunar_ndays==30)
	{
		MaxMini = "小";
	}
	//计算月历中第一天的农历日期
	Lyear = year;
	Lmonth_index = row * 14 + line;
	Lmonth = MonOrder[Lmonth_index] - 1;//农历月,从十一月开始(即冬至所在农历月为首)
	if (Lmonth < 1)
	{
		Lmonth += 12;
	}
	if (Lmonth > 10 && ((row * 14 + line) % 14 < 2))
	{
		Lyear--;
	}
	Lday = dM0 - MonHead[row * 15 + line];//农历日则是距农历月首天数来计算
	//计算节气日期所在位置
	dM0_lunar = Lday;
	dM_lunar = dM0_lunar;
	for (index_Solterms = (month - 1) * 2; index_Solterms < 24; index_Solterms++)
	{
		Solterms1 = SolTerms[row * 24 + index_Solterms];
		Solterms2 = SolTerms[row * 24 + index_Solterms + 1];
		if (int2(Solterms1 + 0.5) <= (dM0 + 14) && int2(Solterms2 + 0.5) > (dM0 + 14))
		{
			break;
		}
	}
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE |
		FOREGROUND_RED);
	printf("\r\n\t\t公历  %d年%d月  %s%s\r\n\r\n", year, month, Week[(base_days + 142113) % 7], leap);
	SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
	SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);
	printf("  周日\t");
	SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
	printf("  周一\t  周二\t  周三\t  周四\t  周五\t");
	SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);
	printf("  周六\r\n");
	SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
	printf("_________________________________________________________\r\n");
	for (cal_item = 0; cal_item < 7; cal_item++)
	{
		if (!isLunarCal)
		{
			if (fillBlanks)
			{
				if (isfirstline&&dw0 != 0)
				{
					printf("  \t  ");
				}
				if (dw0 == 0)
				{
					printf("");
					cal_item = -1;
				}
				for (idw; idw > 1; idw--)
				{
					printf("\t   ");
					cal_item++;
				}
				idw = dw0;
				fillBlanks = false;
			}
			else
			{
				if (cal_item == 0)
				{
					printf("  ");
				}
				printf("%d\t   ", GreCaday);
				GreCaday++;

				if (cal_item == 5 || cal_item == 6)
				{
					handle = GetStdHandle(STD_OUTPUT_HANDLE);
					SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE |
						FOREGROUND_RED);
				}
				else
				{
					SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
				}
				if (GreCaday > dMn)
				{
					printf("\r\n");
					cal_item = -1;
					isLunarCal = true;
				}
				if (cal_item == 6)
				{
					cal_item = -1;
					printf("\r\n");
					isLunarCal = true;
					if (isfirstline)
					{
						fillBlanks = true;
					}
				}
			}
		}
		else
		{
			if (fillBlanks)
			{
				if (isfirstline&&dw0 != 0)
				{
					printf("  \t ");
				}
				if (dw0 == 0)
				{
					printf("");
					cal_item = -1;
				}
				for (idw; idw > 2; idw--)
				{
					printf("\t   ");
					cal_item++;
				}
				if (dw0 > 1)
				{
					printf("\t ");
					cal_item++;
				}
				fillBlanks = false;
			}
			else
			{
				if (dM_lunar >= lunar_ndays)
				{
					Lmonth_index++;
					Lmonth = MonOrder[Lmonth_index] - 1;
					if (Lmonth < 1)
					{
						Lmonth += 12;
					}
					if (Lmonth > 10)
					{
						year--;
					}
					lunar_ndays = MonHead[row * 15 + line + 2] - MonHead[row * 15 + line + 1];
					dM_lunar = 0;
				}
				if (cal_item == 0 || cal_item == 6)
				{
					handle = GetStdHandle(STD_OUTPUT_HANDLE);
					SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE |
						FOREGROUND_RED);
				}
				else
				{
					SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
				}
				if (int2(Solterms1 + 0.5) == CriDay_day)
				{
					if (cal_item == 0)
					{
						printf(" ");
					}
					HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
					SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);
					printf("%s", Solterms[(index_Solterms) % 24]);
					SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
				}
				else if (int2(Solterms2 + 0.5) == CriDay_day)
				{
					if (cal_item == 0)
					{
						printf(" ");
					}
					HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
					SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);
					printf("%s", Solterms[(index_Solterms)+1 % 24]);
					SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
				}
				else
				{
					if (dM_lunar == 0)
					{
						if (MonOrder[Lmonth_index] == MonOrder[Lmonth_index - 1])
						{
							printf("闰");
						}
						else
						{
							if (cal_item == 0)
							{
								printf(" ");
							}
						}
						printf("%s", mName[Lmonth - 1]);
						if (lunar_ndays == 30)
						{
							printf("大");
						}
						else
						{
							printf("小");
						}
					}
					else
					{
						if (cal_item == 0)
						{
							printf(" ");
						}
						printf("%s", dName[dM_lunar]);
					}
				}
				CriDay_day++;
				dM_lunar++;
				LunCaday++;
				if (dM_lunar == lunar_ndays)
				{
					if (MonOrder[Lmonth_index + 1] == MonOrder[Lmonth_index])
					{
						printf(" ");
					}
					else
					{
						printf("\t");
					}
				}
				else
				{
					if (MonOrder[Lmonth_index - 1] == MonOrder[Lmonth_index])
					{
						if (dM0_lunar == 0)
						{
							printf(" ");
						}
						else
						{
							printf("\t ");
						}
					}
					else
					{
						printf("\t ");
					}
				}
				if (LunCaday > dMn)
				{
					break;
				}
				if (cal_item == 6)
				{
					cal_item = -1;
					printf("\r\n\r\n");
					isLunarCal = false;
					if (isfirstline)
					{
						isfirstline = false;
					}
					if (LunCaday > dMn)
					{
						break;
					}
				}
			}
		}
	}
	printf("\r\n_________________________________________________________\r\n");
}

int GetDaysOfMonth(int year, int month, bool mode, bool bLeap)
{
	int dM0 = 0, dMn = 0;
	if (!mode)
	{
		dM0 = CriterionDay(year, month, 1);				//月首天数
		if (month == 12)
		{
			dMn = CriterionDay(++year, 1, 1) - dM0;			//元旦
		}
		else
		{
			dMn = CriterionDay(year, ++month, 1) - dM0;		//下个月
		}
	}
	else
	{
		int leap_Month = -1;						//农历闰月所在位置
		int row = year - start_year;				//所在行
		int i = 0;
		int line = month + 1;
		for (i = 0; i < 14; i++)
		{
			if (MonOrder[row * 14 + i + 1] == MonOrder[row * 14 + i])
			{
				leap_Month = i - 1;
				break;
			}
		}
		if (leap_Month == -1)
		{
			if (bLeap)
			{
				return -1;					//如果当前年份无闰月,而输入有闰月,则返回-1,以代表输入错误
			}
		}
		else
		{
			if (bLeap)
			{
				if (leap_Month != month)
				{
					return -1;			//当前年份有闰月,但并非当前输入月份
				}
			}
		}
		if (leap_Month != -1)
		{
			if (month > leap_Month)		//在当年闰月以及之后
			{

				line++;
			}
			else
			{
				if (bLeap == true && month == leap_Month)
				{
					line++;
				}
			}
		}
		dMn = MonHead[row * 15 + line + 1] - MonHead[row * 15 + line];
	}
	return dMn;//返回当前公历月份的天数
}

/*查询某天农历和节气*/
void DateRefer(int year, int month, int day, bool SST)
{
	int Lyear = 0, Lmonth = 0, Lday = 0;
	int base_days = 0;			//基准日
	int row = 0, line = 0;			//行与列
	int i = 0, SoTer = 0, SoTer1 = 0;		//节气
	const char *leap="";				//闰月
	const char *MaxMini="";			//大月或小月
	Lyear = year;
	base_days = CriterionDay(year, month, day);
	row = year - start_year;
	line = month - 1;

	for (line; line < 15; line++)
	{
		if ((MonHead[row * 15 + line - 1] <= base_days) && (MonHead[row * 15 + line] > base_days))
		{
			break;
		}
	}
	line--;//减掉多加的1
	if (MonOrder[row * 14 + line - 1] == MonOrder[row * 14 + line])
	{
		leap = "闰";
	}
	if ((MonHead[row * 15 + line + 1] - MonHead[row * 15 + line]) == 31)
	{
		MaxMini = "大";
	}
	else
	{
		MaxMini = "小";
	}
	Lmonth = MonOrder[row * 14 + line] - 1;
	if (Lmonth < 1)
	{
		Lmonth += 12;
	}
	if (Lmonth > 10 && ((row * 14 + line) % 14 < 2))
	{
		Lyear--;//对于十一月和十二月的,年份应为上一年的
	}
	Lday = base_days - MonHead[row * 15 + line];//从初一开始

	if (SST)        //SST为true时,显示农历不显示节气
	{
		HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);				//获取控制台句柄
		SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE | FOREGROUND_RED);   	//更改文字颜色,为粉色
		printf("%s%s年 %s%s(%s)%s", HeavenlySte[(Lyear - 1984 + 9000) % 10],EarthlyBran[(Lyear - 1984 + 9000) % 12], leap, mName[Lmonth - 1], MaxMini, dName[Lday]);
		SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
	}
	else
	{
		HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);				//获取控制台句柄
		SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE | FOREGROUND_RED);   	//更改文字颜色,为粉色
		printf("\n\t\t农历  %s%s[%s]年 %s%s(%s)%s\t\n", HeavenlySte[(Lyear - 1984 + 9000) % 10],EarthlyBran[(Lyear - 1984 + 9000) % 12], ChineseZod[(Lyear - 1984 + 9000) % 12],
			leap, mName[Lmonth - 1], MaxMini, dName[Lday]);
		SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
		for (i = (month - 1) * 2; i < 48; i++)
		{
			SoTer = int2(SolTerms[row * 24 + i] + 0.5);
			SoTer1 = int2(SolTerms[row * 24 + i + 1] + 0.5);
			if (SoTer1 > base_days&&SoTer <= base_days)
			{
				if (SoTer == base_days)
				{
					LONGTIME lt = GetDate(SolTerms[row * 24 + i]);
					printf("\n\t今日节气:");
					HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);				//获取控制台句柄
					SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);   	//更改文字颜色,为红色
					printf("%s", Solterms[i % 24]);
					SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
					printf(" 交节时间:");
					SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);   	//更改文字颜色,为红色
					printf("%d-%d-%d %02d:%02d:%02d\r\n\r\n", lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond);
					SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
				}
				else
				{
					printf("\n\t距离下一个节气『");
					HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);				//获取控制台句柄
					SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);   	//更改文字颜色,为红色
					printf("%s", Solterms[(i + 1) % 24]);
					SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
					printf("』还有");
					SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);   	//更改文字颜色,为红色
					printf("%d", SoTer1 - base_days);
					SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
					printf("天\n");
				}
				break;
			}
		}
	}
}
/*基准天数计算*/
int CriterionDay(int year,int month,int day)
{
	int basedays = 0;
	int x = 0, y = 0;
	if (month <= 2 && month > 0)
	{
		year--;
		month += 12;
	}
	x = (int)(year / 100);
	y = 0;
	if (year == 1582)
	{
		if (month == 10)
		{
			if (day >= 15)
			{
				y = 2 - x + (int)(x / 4);
			}
		}
		else if (month > 10)
		{
			y = 2 - x + (int)(x / 4);
		}
	}
	else if (year > 1582)
	{
		y = 2 - x + (int)(x / 4);
	}
	basedays = (int)(365.25*(year + 16)) + 36525 * 47 + (int)(30.6001*(month + 1)) + day + y - 2453069;
	return basedays;
}

/*获得小于等于该数的整数*/
int int2(double v)
{
	int a = (int)v;
	if (v < 0)
	{
		double rm = GetDecimal(v);
		if (rm != 0)
		{
			a--;
		}
	}
	return a;
}

/*获取小数部分,对负数取负部分*/
double GetDecimal(double n)
{
	n -= (int)n;
	return n;
}

/*将小数日转公历*/
LONGTIME GetDate(double n)
{
	LONGTIME lt;
	double A, F, D;
	int x = 0;
	n += 0.5;
	x += 2;
	x *= 10;
	x += 4;
	x *= 10;
	x += 5;
	x *= 10;
	x += 1;
	lt.wYear = 0;
	lt.wMonth = 0;
	lt.wDay = 0;
	lt.wHour = 0;
	lt.wMinute = 0;
	lt.wSecond = 0;
	lt.wMillisecond = 0;
	x *= 10;
	x += 5;
	x *= 10;
	x += 4;
	x *= 10;
	x += 5;
	n += x;
	lt.wDayOfWeek = ((int2)(n + 1)) % 7;
	A = (int)n;
	F = n - A;
	if (A >= 2299161)
	{
		D = (int)((A - 1867216.25) / 36524.25);
		A += 1 + D - (int)(D / 4);
	}
	A += 1524;
	lt.wYear = (int)((double)(A - 122.1) / 365.25);
	D = A - (int)(365.25*lt.wYear);
	lt.wMonth = (int)(D / 30.6001);
	lt.wDay = (int)(D - (int)(lt.wMonth*30.6001));
	lt.wYear -= 4716;
	lt.wMonth--;
	if (lt.wMonth > 12)
	{
		lt.wMonth -= 12;
	}
	if (lt.wMonth <= 2)
	{
		lt.wYear++;
	}
	F *= 24;
	lt.wHour = (int)F;
	F -= lt.wHour;
	F *= 60;
	lt.wMinute = (int)F;
	F -= lt.wMinute;
	F *= 60;
	lt.wSecond = (int)F;
	F -= lt.wSecond;
	F *= 1000;
	lt.wMillisecond = (int)F;
	return lt;
}

/*农历查公历*/
int GetGre(LUNARDATE LunarDate)
{
	int row = LunarDate.iYear - start_year;
	int line = LunarDate.wMonth + 1;
	int leap_month = -1;
	int i = 0;
	double ndays = 0.0;
	int ileapMonth = 0;
	int dMn = 0;
	LONGTIME lt;
	for (i = 0; i < 14; i++)
	{
		if (MonOrder[row * 14 + i + 1] == MonOrder[row * 14 + i])
		{
			leap_month = i - 1;//农历闰月
			if (leap_month <= 0)
			{
				leap_month += 12;
			}
			break;
		}
	}
	if (leap_month == LunarDate.wMonth)
	{
		printf("当前月份是否为闰月?(是闰月则输入“Y”,否则输入“N”)>");
		ileapMonth = _getche();
		if (ileapMonth == 89 || ileapMonth == 121)
		{
			LunarDate.blsLeap = true;
		}
		else if (ileapMonth == 78 || ileapMonth == 110)
		{
			LunarDate.blsLeap = false;
		}
		printf("\r\n");
	}
	dMn = GetDaysOfMonth(LunarDate.iYear, LunarDate.wMonth, true, LunarDate.blsLeap);
	if (dMn == -1)
	{
		printf("当前农历闰月信息有误,请重新输入:Year Month Day>");
		return 2;//返回错误
	}
	else
	{
		if (dMn < LunarDate.wDay)
		{
			if (LunarDate.blsLeap)
			{
				printf("%d年闰%s只有 %d 天,请重新输入:Year Month Day>", LunarDate.iYear, mName[LunarDate.wMonth - 1], dMn);
			}
			else
			{
				printf("%d年%s只有 %d 天,请重新输入:Year Month Day>", LunarDate.iYear, mName[LunarDate.wMonth - 1], dMn);
			}
			return 1;
		}
	}
	if (leap_month != -1)
	{
		//定位当前列
		if (LunarDate.wMonth > leap_month)
		{
			line++;
		}
		else
		{
			if (LunarDate.wMonth == leap_month && LunarDate.blsLeap == true)
			{
				line++;
			}
		}
	}
	ndays = MonHead[row * 15 + line];
	ndays += LunarDate.wDay;
	ndays--;
	lt = GetDate(ndays);
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);				//获取控制台句柄
	SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);   	//更改文字颜色,为红色
	printf("\r\n%d (%s%s)年 [%s] ", LunarDate.iYear, HeavenlySte[(LunarDate.iYear - 1984 + 9000) % 10], EarthlyBran[(LunarDate.iYear - 1984 + 9000) % 12], ChineseZod[(LunarDate.iYear - 1984 + 9000) % 12]);
	if (LunarDate.blsLeap)
	{
		printf("闰");
	}
	printf("%s%s ", mName[LunarDate.wMonth - 1], dName[LunarDate.wDay - 1]);
	SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);		//恢复颜色
	printf("的公历日期为:");
	SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);
	printf("%d年%d月%d日 %s\r\n", lt.wYear, lt.wMonth, lt.wDay, Week[lt.wDayOfWeek]);
	SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);		
	return 0;
}

/*获得当前日期*/
LONGTIME GetCurTime()
{
	SYSTEMTIME st;
	LONGTIME lt;
	GetSystemTime(&st);
	lt = SysTimeToLong(st);
	lt = GMTConvert(lt);
	return lt;
}

/*时间结构体转换*/
LONGTIME SysTimeToLong(SYSTEMTIME SystemTime)
{
	LONGTIME LongTime;
	LongTime.wYear = (long int)SystemTime.wYear;
	LongTime.wMonth = SystemTime.wMonth;
	LongTime.wDay = SystemTime.wDay;
	LongTime.wHour = SystemTime.wHour;
	LongTime.wMinute = SystemTime.wMinute;
	LongTime.wSecond = SystemTime.wSecond;
	LongTime.wMillisecond = SystemTime.wMilliseconds;
	LongTime.wDayOfWeek = SystemTime.wDayOfWeek;
	return LongTime;
}

/*时区转换*/
LONGTIME GMTConvert(LONGTIME OrigTime)
{
	//从零时区转换到系统当前时区
	int m_hour = 0, m_day = 0, m_month = 0, m_year = 0, m_minute = 0, m_second = 0, zone = 0;
	TIME_ZONE_INFORMATION stTimeZone;
	ZeroMemory(&stTimeZone, sizeof(TIME_ZONE_INFORMATION));
	GetTimeZoneInformation(&stTimeZone);//获取当前时区
	zone = 0 - stTimeZone.Bias / 60;
	m_year = OrigTime.wYear;
	m_month = OrigTime.wMonth;
	m_day = OrigTime.wDay;
	m_hour = OrigTime.wHour;
	m_minute = OrigTime.wMinute;
	m_second = OrigTime.wSecond;
	if (m_hour >= 24 - zone)
	{
		//需要加一天
		m_hour = m_hour - 24 + zone;
		if (OrigTime.wDayOfWeek < 7)
		{
			OrigTime.wDayOfWeek++;
		}
		else
		{
			OrigTime.wDayOfWeek = OrigTime.wDayOfWeek - 6;
		}
		/*平年,闰年判断条件*/
		if (IsLeapYear(m_year))
		{
			if (m_month == 2)//2月为29天
			{
				if (m_day == 29)
				{
					m_month++;
					m_day = 1;
				}
				else
				{
					m_day++;//条件内,如果小于29天,+1
				}
			}
			else if (m_month == 1 || m_month == 3 || m_month == 5 || m_month == 7 || m_month == 8 || m_month == 10)//一年当中1,3,5,7,8,10月为31天。
			{
				if (m_day == 31)
				{
					m_month++;
					m_day = 1;
				}
				else
				{
					m_day++;//条件内,如果小于31天,+1
				}
			}
			else if (m_month == 4 || m_month == 6 || m_month == 9 || m_month == 11)//一年当中4,6,9,11月为30天。
			{
				if (m_day == 30)
				{
					m_month++;
					m_day = 1;
				}
				else
				{
					m_day++;
				}
			}
			else if (m_month == 12)//12月为31天。
			{
				if (m_day == 31)
				{
					m_month = 1;
					m_day = 1;
					m_year++;
				}
				else
				{
					m_day++;
				}
			}
		}
		else
		{
			if (m_month == 2)
			{
				if (m_day == 28)
				{
					m_month++;
					m_day = 1;
				}
				else
				{
					m_day++;
				}
			}
			else if (m_month == 1 || m_month == 3 || m_month == 5 || m_month == 7 || m_month == 8 || m_month == 10)
			{
				if (m_day == 31)
				{
					m_month++;
					m_day = 1;
				}
				else
				{
					m_day++;
				}
			}
			else if (m_month == 4 || m_month == 6 || m_month == 9 || m_month == 11)
			{
				if (m_day == 30)
				{
					m_month++;
					m_day = 1;
				}
				else
				{
					m_day++;
				}
			}
			else if (m_month == 12)
			{
				if (m_day == 31)
				{
					m_month = 1;
					m_day = 1;
					m_year++;
				}
				else
				{
					m_day++;
				}
			}
		}
	}
	else
	{
		m_hour = m_hour + zone;
	}
	OrigTime.wYear = m_year;
	OrigTime.wMonth = m_month;
	OrigTime.wDay = m_day;
	OrigTime.wHour = m_hour;
	OrigTime.wMinute = m_minute;
	OrigTime.wSecond = m_second;
	return OrigTime;
}

/*判断所传入的年份是否为闰年*/
bool IsLeapYear(int nYear)
{
	if (nYear > 1582)
	{
		if (nYear % 4 == 0 && nYear % 100 != 0 || nYear % 400 == 0)//能被4整除,不能被100整除,或可以被400整除的为闰年。
		{
			return true;
		}
		else
		{
			return false;
		}
		return true;
	}
	else if (nYear > -4713)
	{
		if (nYear % 4 == 0)
		{
			return true;
		}
		else
		{
			return false;
		}
		return true;
	}
	return false;
}

/*显示二十四节气*/
void ShowSolarTerms(int year)
{
	int row = year - start_year;
	int line = 3;//从立春开始算。
	LONGTIME lt;
	printf("\r\n  节气名称\t交节日期\t交节时间\t  农历\t\t星期\r\n");
	printf("----------------------------------------------------------------------\r\n");
	for (line; line < 27; line++)//因为lie初始为3,则算24个节气后,为26,因此小于27
	{
		lt = GetDate(SolTerms[row * 24 + line]);
		printf("  %02d. ", line - 2);
		HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);				//获取控制台句柄
		SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);   	//更改文字颜色,为红色
		printf("%s", Solterms[line % 24]);
		SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
		printf("  \t%d-%d-%d\t%02d:%02d:%02d  ", lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond);

		DateRefer(lt.wYear, lt.wMonth, lt.wDay, true);
		if (line == 26)
		{
			printf("  %s\r\n", Week[lt.wDayOfWeek]);
		}
		else
		{
			printf("  %s\r\n\r\n", Week[lt.wDayOfWeek]);
		}
	}
	printf("----------------------------------------------------------------------\r\n");
}

/*获得公历节日*/
void Holiday(int month)
{
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);				//获取控制台句柄
	switch (month)
	{
	case 1:
		SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);	//蓝字
		printf("\n\t\t 1月1日元旦(New Year's Day)\n");
		printf("\t\t 1月最后一个星期日国际麻风节(International Lepresi Day)\n\n");
		SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);		//恢复文字颜色
		break;
	case 2:
		SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);	//蓝字
		printf("\n\t\t 2月2日  世界湿地日(World Wetlands Day)\n");
		printf("\t\t 2月14日 情人节(Valentine's Day)\n\n");
		SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);		
		break;
	case 3:
		SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);	//蓝字
		printf("\n\t\t 3月3日  全国爱耳日(Ear Car Day)\n");
		printf("\t\t 3月5日  青年志愿者服务日(Youth Volunter Service Day)\n");
		printf("\t\t 3月8日  国际妇女节(International Women' Day)\n");
		printf("\t\t 3月9日  保护母亲河日(Protect Mother River Day)\n");
		printf("\t\t 3月12日 中国植树节(China Arbor Day)\n");
		printf("\t\t 3月14日 白色情人节(White Valentine's Day)\n");
		printf("\t\t 3月14日 国际警察日(International Policemen' Day)\n");
		printf("\t\t 3月15日 世界消费者权益日(World Consumer Right Day)\n");
		printf("\t\t 3月21日 世界森林日(World Forest Day)\n");
		printf("\t\t 3月21日 世界睡眠日(World Sleep Day)\n");
		printf("\t\t 3月22日 世界水日(World Water Day)\n");
		printf("\t\t 3月23日 世界气象日(World Meteorological Day)\n");
		printf("\t\t 3月24日 世界防治结核病日(World Tuberculosis Day)\n");
		printf("\t\t 3月最后一个完整周的星期一中小学生安全教育日\n\n");
		SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);		
		break;
	case 4:
		SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);	//蓝字
		printf("\n\t\t 4月1日  愚人节(April Fools' Day)\n");
		printf("\t\t 4月5日  清明节(Tomb-sweeping Day)\n");
		printf("\t\t 4月7日  世界卫生日(World Health Day)\n");
		printf("\t\t 4月22日 世界地球日(World Earth Day)\n");
		printf("\t\t 4月26日 世界知识产权日(World Intellectual PropertyDay)\n\n");
		SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);		
		break;
	case 5:
		SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);	//蓝字
		printf("\n\t\t 5月1日  国际劳动节(International Labour Day)\n");
		printf("\t\t 5月3日  世界哮喘日(World Asthma Day)\n");
		printf("\t\t 5月4日  中国青年节(Chinese Youth Day)\n");
		printf("\t\t 5月8日  世界红十字日(World Red-Cross Day)\n");
		printf("\t\t 5月12日 国际护士节(International Nurse Day)\n");
		printf("\t\t 5月15日 国际家庭日(International Family Day)\n");
		printf("\t\t 5月17日 世界电信日(World Telecommunications Day)\n");
		printf("\t\t 5月20日 全国学生营养日(National Student Nutrition Day)\n");
		printf("\t\t 5月23日 国际牛奶日(International Milk Day)\n");
		printf("\t\t 5月31日 世界无烟日(World No-Smoking Day)\n");
		printf("\t\t 5月第二个星期日母亲节(Mother's Day)\n");
		printf("\t\t 5月第三个星期日全国助残日(National Disabled Day)\n\n");
		SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);		
		break;
	case 6:
		SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);	//蓝字
		printf("\n\t\t 6月1日  国际儿童节(International Children's Day)\n");
		printf("\t\t 6月5日  世界环境日(International Environment Day)\n");
		printf("\t\t 6月6日  全国爱眼日(National Eye Day)\n");
		printf("\t\t 6月17日 世界防治荒漠化和干旱日(World Day to combat desertification)\n");
		printf("\t\t 6月23日 国际奥林匹克日(International Olympic Day)\n");
		printf("\t\t 6月25日 全国土地日(National Land Day)\n");
		printf("\t\t 6月26日 国际禁毒日(International Day Against Drug Abuse and Illicit Trafficking)\n");
		printf("\t\t 6月第三个星期日父亲节(Father's Day)\n\n");
		SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);		
		break;
	case 7:
		SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);	//蓝字
		printf("\n\t\t 7月1日  中国共产党诞生日(Anniversary of the Founding of the Chinese Communist Party)\n");
		printf("\t\t 7月1日  国际建筑日(International Architecture Day)\n");
		printf("\t\t 7月7日  中国人民抗日战争纪念日(Chinese People Sino-Japanese War Commemoration Day)\n");
		printf("\t\t 7月11日 世界人口日(World Population Day)\n\n");
		SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);		
		break;
	case 8:
		SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);	//蓝字
		printf("\n\t\t 8月1日  中国人民解放军建军节(Army Day)\n");
		printf("\t\t 8月12日 国际青年节(International Youth Day)\n\n");
		SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);		
		break;
	case 9:
		SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);	//蓝字
		printf("\n\t\t 9月8日  国际扫盲日(International Anti-illiteracy Day)\n");
		printf("\t\t 9月10日 中国教师节(Teacher's Day)\n");
		printf("\t\t 9月16日 中国脑健康日(Brain Health Day)\n");
		printf("\t\t 9月16日 国际臭氧层保护日(International Day for the Preservation of the Ozone Layer)\n");
		printf("\t\t 9月20日 全国爱牙日(Love Toth Day)\n");
		printf("\t\t 9月21日 世界停火日(World Cease-fire Day)\n");
		printf("\t\t 9月27日 世界旅游日(World Tourism Day)\n");
		printf("\t\t 9月第三个星期二国际和平日(International Peace Day)\n");
		printf("\t\t 9月第三个星期六全国国防教育日(National Defense Education Day)\n");
		printf("\t\t 9月第四个星期日国际聋人节(International Day of the Deaf)\n\n");
		SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);		
		break;
	case 10:
		SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);	//蓝字
		printf("\n10月1日  中华人民共和国国庆节(National Day)\n");
		printf("\t\t 10月1日  国际音乐日(International Music Day)\n");
		printf("\t\t 10月1日  国际老年人日(International Day of Older Persons)\n");
		printf("\t\t 10月4日  世界动物日(World Animal Day)\n");
		printf("\t\t 10月5日  世界教师日(World Teachers' Day)(联合国教科文组织确立)\n");
		printf("\t\t 10月8日  全国高血压日(Hypertension Day)\n");
		printf("\t\t 10月9日  世界邮政日(World Post Day)\n");
		printf("\t\t 10月10日 世界精神卫生日(World Mental Health Day)\n");
		printf("\t\t 10月14日 世界标准日(World Standards Day)\n");
		printf("\t\t 10月15日 国际盲人节(International Day of the Blind)\n");
		printf("\t\t 10月15日 世界农村妇女日(World Rural Women's Day)\n");
		printf("\t\t 10月16日 世界粮食日(World Food Day)\n");
		printf("\t\t 10月17日 国际消除贫困日(International Day for the Eradication of Poverty)\n");
		printf("\t\t 10月24日 联合国日(United Nations Day)\n");
		printf("\t\t 10月24日 世界发展新闻日(World Development Information Day)\n");
		printf("\t\t 10月28日 中国男性健康日(Chinese Men's Health Day)\n");
		printf("\t\t 10月29日 国际生物多样性日(International Biodiversity Day)\n");
		printf("\t\t 10月31日 万圣节(Halloween)\n");
		printf("\t\t 10月的第一个星期一世界住房日(World Habitat Day)\n");
		printf("\t\t 10月的第二个星斯一加拿大感恩节(Thanksgiving Day)\n");
		printf("\t\t 10月第二个星期三国际减轻自然灾害日(International Day for Natural Disaster Reduction)\n");
		printf("\t\t 10月第二个星期四世界爱眼日(World Sight Day)\n\n");
		SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);		
		break;
	case 11:
		SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);	//蓝字
		printf("\n\t\t 11月8日  中国记者节(Chinese Journalist's Day)\n");
		printf("\t\t 11月9日  消防宣传日(Fire Protection Publicity Day)\n");
		printf("\t\t 11月14日 世界糖尿病日(World Diabetes Day)\n");
		printf("\t\t 11月17日 国际大学生节(International University Day)\n");
		printf("\t\t 11月25日 国际消除对妇女的暴力日(International Day For the elimination of Violence against Women)\n");
		printf("\t\t 11月最后一个星期四美国感恩节(Thanksgiving Day)\n\n");
		SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);		
		break;
	case 12:
		SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);	//蓝字
		printf("\n\t\t 12月1日  世界爱滋病日(World AIDS Day)\n");
		printf("\t\t 12月3日  世界残疾人日(World Disabled Day)\n");
		printf("\t\t 12月4日  全国法制宣传日(National Legal Publicity Day)\n");
		printf("\t\t 12月9日  世界足球日(World Football Day)\n");
		printf("\t\t 12月25日 圣诞节(Christmas Day)\n");
		printf("\t\t 12月29日 国际生物多样性日(International Biological Diversity Day)\n\n");
		SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);		
		break;
	}
}

提示:SetConsoleTextAttribute():用来设置控制台文本颜色和背景色的函数。
函数原型:BOOL SetConsoleTextAttribute(HANDLE,hConsoleOutput,WORD wAttribute);/*hConsoleOutput:控制台屏幕输出流句柄。文件流句柄需以(GENERIC_READ)颜色属性值为写入权限。WORD wAttribute:用来设置颜色*/

常用wAttribute色彩属性值表如下:

参数值 含义
FOREGROUND_BLUE 前景蓝色
FOREGROUND_GREEN 前景绿色
FOREGROUND_RED 前景红色
FOREGROUND_INTENSITY 前景色彩高亮强度
BACKGROUND_BLUE 背景蓝色
BACKGROUND_GREEN 背景绿色
BACKGROUND_RED 背景红色
BACKGROUND_INTENSITY 背景色彩高亮强度

因篇幅过长系统提示“此文章阅读完大约需要2个多小时,请优化”。故"Calendar.h"头文件已上传为资源,具体注意事项将以注释的方式写入头文件。请自行查阅。
资源链接:https://download.csdn.net/download/qq_31293403/86507411

本文含有隐藏内容,请 开通VIP 后查看