C 언어 - 어제 시간 정보 계산
23957 단어 기술성
//
//
// ,
#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(" :
");
printf(" :20%d %d %d
",ComputingTime.year,ComputingTime.month,ComputingTime.day);
// printf(" :20%d %d %d
",ComputingTime->year,ComputingTime->month,ComputingTime->day);
ComputingLastThreeDaysTime(&SystemTime,&ComputingTime);
printf(" :20%d %d %d
",ComputingTime.year,ComputingTime.month,ComputingTime.day);
//printf(" :20%d %d %d
",ComputingTime->year,ComputingTime->month,ComputingTime.day);
return 0;
}