Code是乱乱边吐血边算出来的,请亲们转的时候带上地址
TransSystemTime为函数入口
获取到的秒数为4个8bit数,转换为g_bSystemTime,是32位无符号整型高位数
另外关于时区(timezone)的问题,如果是东区就+,西区就-
验证时可以使用数据:
DATA8 = 0x04;
DATA9 = 0x50;
DATA10 = 0x12;
DATA11 = 0xbc;
DATA12 = 0x6e;
转换后的时间是
year:2012
month:7
day:27
hour:16
minute:6
second:6
-----------------------------------------------------------------------------------------------
g_bSystemTime = 0;
g_bSystemTime = g_bSystemTime | DATA9;
g_bSystemTime = (g_bSystemTime << 8) | DATA10;
g_bSystemTime = (g_bSystemTime << 8) | DATA11;
g_bSystemTime = (g_bSystemTime << 8) | DATA12;
void GetMDofSystemTime(BYTE days, BYTE isRunyear)
{
if(isRunyear)
{
if(days <= 31)
{
dSystemTime.month = 1;
dSystemTime.day = days;
}
else if(days <= 60)
{
dSystemTime.month = 2;
dSystemTime.day = days - 31;
}
else if(days <= 91)
{
dSystemTime.month = 3;
dSystemTime.day = days - 60;
}
else if(days <= 121)
{
dSystemTime.month = 4;
dSystemTime.day = days - 91;
}
else if(days <= 152)
{
dSystemTime.month = 5;
dSystemTime.day = days - 121;
}
else if(days <= 182)
{
dSystemTime.month = 6;
dSystemTime.day = days - 152;
}
else if(days <= 213)
{
dSystemTime.month = 7;
dSystemTime.day = days - 182;
}
else if(days <= 244)
{
dSystemTime.month = 8;
dSystemTime.day = days - 213;
}
else if(days <= 274)
{
dSystemTime.month = 9;
dSystemTime.day = days - 244;
}
else if(days <= 305)
{
dSystemTime.month = 10;
dSystemTime.day = days - 274;
}
else if(days <= 335)
{
dSystemTime.month = 11;
dSystemTime.day = days - 305;
}
else
{
dSystemTime.month = 12;
dSystemTime.day = days - 335;
}
}
else
{
if(days <= 31)
{
dSystemTime.month = 1;
dSystemTime.day = days;
}
else if(days <= 59)
{
dSystemTime.month = 2;
dSystemTime.day = days - 31;
}
else if(days <= 90)
{
dSystemTime.month = 3;
dSystemTime.day = days - 59;
}
else if(days <= 120)
{
dSystemTime.month = 4;
dSystemTime.day = days - 90;
}
else if(days <= 151)
{
dSystemTime.month = 5;
dSystemTime.day = days - 120;
}
else if(days <= 181)
{
dSystemTime.month = 6;
dSystemTime.day = days - 151;
}
else if(days <= 212)
{
dSystemTime.month = 7;
dSystemTime.day = days - 181;
}
else if(days <= 243)
{
dSystemTime.month = 8;
dSystemTime.day = days - 212;
}
else if(days <= 273)
{
dSystemTime.month = 9;
dSystemTime.day = days - 243;
}
else if(days <= 304)
{
dSystemTime.month = 10;
dSystemTime.day = days - 273;
}
else if(days <= 334)
{
dSystemTime.month = 11;
dSystemTime.day = days - 304;
}
else
{
dSystemTime.month = 12;
dSystemTime.day = days - 334;
}
}
}
void TransSystemTime(ULONG systemtime)
{
ULONG tempsec;
UINT tempday1;
UINT tempday2;
UINT tempyear1;
UINT tempyear2;
BYTE timezone = 0x09; //japan time zone east 9 zone
dSystemTime.year = 0;
dSystemTime.month = 0;
dSystemTime.day = 0;
dSystemTime.second = 0;
dSystemTime.minute = 0;
dSystemTime.hour = 0;
//systemtime = systemtime + (3600*timezone);
tempsec = systemtime % 86400; //time of one day
dSystemTime.second = tempsec % 60;
dSystemTime.minute = (tempsec /60)%60;
dSystemTime.hour = (tempsec /(60*60));
tempyear1 = ((systemtime / 86400) /(365*4+1)); // tempyear1 4 years
tempday1 = ((systemtime / 86400)%(365*4+1));
tempyear2 = tempday1/365;
tempday2 = tempday1 %365+1;
switch(tempyear2)
{
case 0:
case 1:
GetMDofSystemTime(tempday2, FALSE);
break;
case 2:
GetMDofSystemTime(tempday2, TRUE);
break;
case 3:
tempday2 = tempday2 - 1;
if(tempday2 == 0)
{
tempyear2 = 2;
dSystemTime.month = 12;
dSystemTime.day = 31;
}
else
GetMDofSystemTime(tempday2, FALSE);
break;
}
dSystemTime.year = 1970+tempyear1*4 +tempyear2;
printf("year:%d\n",dSystemTime.year);
printf("month:%d\n",dSystemTime.month);
printf("day:%d\n",dSystemTime.day);
printf("hour:%d\n",dSystemTime.hour);
printf("minute:%d\n",dSystemTime.minute);
printf("second:%d\n",dSystemTime.second);
}
Code是乱乱边吐血边算出来的,请亲们转的时候带上地址