由两个unix时间戳得到之间相差自然日数
这两个函数模块是我在参加一个新项目的编写时偶然发现并且特别依赖的部分,为实现当时手上累计登陆完成任务有很大的帮助。该模块用C++编写,在linux环境上编译测试通过
#include <time.h>
int GetTimeZone()
{
time_t tm1, tm2;
tm1 = time( NULL );
struct tm stTm;
tm2 = mktime( gmtime_r( &tm1, &stTm ) );
return static_cast<int>( tm1 - tm2 );
}
int GetDiffDay( unsigned int nTime1, unsigned int nTime2 )
{
static int nDaySec = 3600 * 24;
static int nZone = GetTimeZone();
int nTempTimeSec = 0;
nTempTimeSec = (nZone >= 0)?nZone:(nZone + nDaySec);
int nDay1 = ( nTime1 + nTempTimeSec ) / nDaySec;
int nDay2 = ( nTime2 + nTempTimeSec ) / nDaySec;
return nDay2 - nDay1;
}
下次有空把整个项目用到的时间处理的模块整理一下