C语言-计算昨天的时间信息

//计算昨天的时间信息
//这个程序又重新认识了指针
//指针定义必须初始化,就是必须对指针赋值地址值
#include
/*
#include
#include
#include
using namespace std;
*/

//结构体的定义部分

typedef struct
{
	unsigned char year;
	unsigned char month;
	unsigned char day;
}_SystemTime,_ComputingTime;

/*
typedef struct
{
	unsigned char year;
	unsigned char month;
	unsigned char day;
} _SystemTime;

typedef struct
{
	unsigned char year;
	unsigned char month;
	unsigned char day;
} _ComputingTime;
*/
/*
#define _SystemTime (struct date);
#define _ComputingTime (struct date);
*/
/*
struct date _SystemTime;
struct date _ComputingTime;
*/

//计算昨天时间信息的函数 
void ComputingLastThreeDaysTime( _SystemTime *SystemTime, _ComputingTime *ComputingTime ) //参数1是系统时间,参数2是昨天的时间 
{
	unsigned char year,yearshi,yearge;
	unsigned char month,monthshi,monthge;
	unsigned char day,dayshi,dayge;
	ComputingTime->year = SystemTime->year;
	ComputingTime->month = SystemTime->month;
	ComputingTime->day = SystemTime->day;
	year = ComputingTime->year;
	month = ComputingTime->month;
	day = ComputingTime->day;
	yearshi = ( year & 0xf0 ) >> 4;
	yearge = ( year & 0x0f );
	monthshi = ( month & 0xf0 ) >> 4;
	monthge = ( month & 0x0f );
	dayshi = ( day & 0xf0 ) >> 4;
	dayge = ( day & 0x0f );
	if( dayge == 1 && dayshi == 0 )
 	{
		if( dayshi == 0 )
		{
			if( ( monthge == 0 ) && ( monthshi == 1 ) )
			{
				monthge = 9;
				monthshi = 0;
				dayshi = 3;
				dayge = 0;
			}
			else if( (monthshi == 0 ) && ( monthge == 1 ) )
			{
				monthge = 2;
				monthshi = 1;
				dayshi = 3;
				dayge = 1;
				if( yearge == 0 )
				{
					if( yearshi == 0 )
					{
						year = 9;
					}
					else
					{
						yearshi = yearshi - 1;
					}
				}
				else
				{
					yearge = yearge - 1;
				}
			}
			else
			{
				monthge = monthge - 1;
				if( ( monthshi == 0 ) && ( ( monthge == 1 ) || ( monthge == 3 ) || ( monthge == 5 ) || ( monthge == 7 ) || ( monthge == 8 ) ) )
				{
					dayshi = 3;
					dayge = 1;
				}
				if( ( monthshi == 1 ) && ( ( monthge == 0 ) || ( monthge == 2 ) ) )
				{
					dayshi = 3;
					dayge = 1;
				}
				if( ( monthshi == 0 ) && ( ( monthge == 4 ) || ( monthge == 6 ) || ( monthge == 9 ) ) )
				{
					dayshi = 3;
					dayge = 0;
				}
				if( ( monthshi == 1 ) && ( monthge == 1 ) )
				{
					dayshi = 3;
					dayge = 0;
				}
				if( ( monthshi == 0 ) && ( monthge == 2 ) )
				{
					unsigned int years;
					years = 2000 + yearshi * 10 + yearge;
					if( ( years % 4 == 0 && years % 100 != 0 ) || years % 400 == 0 )
					{
						dayshi = 2;
						dayge = 9;
					}
					else
					{
						dayshi = 2;
						dayge = 8;
					}
				}
			}
		}
		else
		{
			dayshi = dayshi - 1;
		}
	}
	else if( dayge == 0 && dayshi != 0 )
	{
		dayge = 9;
		dayshi = dayshi - 1;
	}
	else
	{
		dayge = dayge - 1;
	}
	year = ( yearshi << 4 ) + yearge;
	month = ( monthshi << 4 ) + monthge;
	day = ( dayshi << 4 ) + dayge;
	ComputingTime->year = year;
	ComputingTime->month = month;
	ComputingTime->day = day;
} 
int main()
{
/*
	_SystemTime *SystemTime;
	_ComputingTime *ComputingTime;
	ComputingTime->year = SystemTime->year = 19;
	ComputingTime->month = SystemTime->month = 4;
	ComputingTime->day = SystemTime->day = 24;
 */
	_SystemTime SystemTime;
	_ComputingTime ComputingTime;
	//此处定义今天的时间信息,可修改
	ComputingTime.year = SystemTime.year = 19;
	ComputingTime.month = SystemTime.month = 4;
	ComputingTime.day = SystemTime.day = 24;
	// cout << "asadasd";
	printf("田贝贝的程序输出:\n");
	printf("今天:20%d年%d月%d日\n",ComputingTime.year,ComputingTime.month,ComputingTime.day);
	// printf("今天:20%d年%d月%d日\n",ComputingTime->year,ComputingTime->month,ComputingTime->day);
	ComputingLastThreeDaysTime(&SystemTime,&ComputingTime);
	printf("昨天:20%d年%d月%d日\n",ComputingTime.year,ComputingTime.month,ComputingTime.day);
	//printf("昨天:20%d年%d月%d日\n",ComputingTime->year,ComputingTime->month,ComputingTime.day);
	return 0;
}

你可能感兴趣的:(技术性)