⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 secondstodate.h

📁 关于彩信的编解码
💻 H
字号:


#define ALLSECONDSINONEDAY	86400	  // 一天的秒数
#define YEARDEADLINE  2100	   // 设2100年为最大期限
#define CIRCLEMAX  128		//循环时的最大长度

I FirstYear = 1970;  
extern MMS_STRUCTION *messmms;

/************************************************
* 天数转换年数,考虑了闰年与否的情况
*************************************************/
I DayToYear(L32 day)
{
	I year;
	I i,countyear = -1,countspecialyear = 0,b;
	for(i = FirstYear; i < YEARDEADLINE; i++)	//	 设2100年为最大期限
	{
		countyear++;
		if(i % 4 == 0)
		{
			countspecialyear++;
			b = 366;
		}
		else
		{
			b = 365;
		}
		if((day - (365 * (countyear -countspecialyear)+ 366*countspecialyear)) >0 && 
			(day -(365 * (countyear -countspecialyear)+ 366*countspecialyear)) <b)
		{
			year = i - FirstYear;
			break;
		}		
	}
	return year;
}

/************************************************
* 通过秒数获得发送时间函数 (通过距离1970-01-01, 00:00:00 GMT的秒数得出)
*************************************************/
DATE CountDate(UL32 allseconds)
{
	DATE d;
	UL32 secondinoneday = ALLSECONDSINONEDAY;  // 一天的秒数
	UL32 alldays,secondexceed1,secondexceed2,dayexceed,Year;
	UL32 i,k=0;

	alldays = allseconds / secondinoneday;	
	secondexceed1 = allseconds % secondinoneday;   
	
	Year = DayToYear(alldays);

	dayexceed = alldays - 365*(Year -Year/4) - Year/4*366;	

	for(i=0;i<12;i++)
	{
		UL32 a[] = {31,28,31,30,31,30,31,31,30,31,30,31};
		if((FirstYear+Year) % 4 ==0)
		{
			a[1] = 29;
		}
		else
		{
			a[1]=28;
		}
		k += a[i];	
		if(dayexceed < k)
		{
			static UL32 temp = k;
			static UL32 itemp = i;
			d.datecontent.month = itemp+1;
			d.datecontent.day =  a[i] - (temp - dayexceed);
		}
	}
	d.datecontent.year = FirstYear + Year;
	d.datecontent.hour = secondexceed1 / 3600;	  
	secondexceed2 = secondexceed1 % 3600;	
	d.datecontent.minute = secondexceed2 / 60;	
	d.datecontent.second = secondexceed2 % 60;	 

	return d;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -