游戏中使用gettimeofday 获取从1970/01/01 00:00:00到现在经过的真实秒数
当进入游戏时使用localtime来判断 tm.tm_isdst是否有从夏令时进出,进入夏令时,调用gettimeofday 和mktime的时间是相同的,离开夏令时,调用gettimeofday 比mktime的时间多3600s
int main()
{
int loop=1000;
cout << "ddd"<<endl;
while(--loop > 0)
{
sleep(1);
struct timeval tv;
gettimeofday(&tv,NULL);
cout << tv.tv_sec << endl;
struct tm _tm;
_tm = *localtime(&(tv.tv_sec));
cout << "hour="<<_tm.tm_hour << " <<<<"<< _tm.tm_isdst << endl;
_tm.tm_isdst=-1;
time_t time = mktime(&_tm);
cout << "time=" << time << " <<<<<<" << _tm.tm_isdst<<endl;
cout << "===="<< _tm.tm_isdst <<endl;
}
}