我是靠谱客的博主 清秀寒风,最近开发中收集的这篇文章主要介绍C语言-计算昨天的时间信息,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

//计算昨天的时间信息
//这个程序又重新认识了指针
//指针定义必须初始化,就是必须对指针赋值地址值
#include<stdio.h>
/*
#include<stdlib.h>
#include<string.h>
#include<iostream>
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;
}

最后

以上就是清秀寒风为你收集整理的C语言-计算昨天的时间信息的全部内容,希望文章能够帮你解决C语言-计算昨天的时间信息所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(39)

评论列表共有 0 条评论

立即
投稿
返回
顶部