我的程序是个Sock程序,在有客户端连接过来时我在OnConnect()中加入下面代码,记录开始时间
time(&LastSaveTime);
char filename[24];
strftime(filename,24,"%Y%m%d%H%M",localtime(&LastSaveTime));
cerr<<"connect"<<filename<<" ="<<LastSaveTime<<endl;在客户端发数据后记录时间
time(&LastSaveTime);
char filename[24];
strftime(filename,24,"%Y%m%d%H%M",localtime(&LastSaveTime));
cerr<<"current"<<filename<<" ="<<LastSaveTime<<endl;客户端连接时间为2002.06.07 12:20,且客户端一连接上便开始发送数据,输出结果为
connect200206071220 =1023423605
current200206071220 =1023481208
为什么两次的LastSaveTime(time_t型变量)值不同,但格式化的字符串确是正确的???
time(&LastSaveTime);
char filename[24];
strftime(filename,24,"%Y%m%d%H%M",localtime(&LastSaveTime));
cerr<<"connect"<<filename<<" ="<<LastSaveTime<<endl;在客户端发数据后记录时间
time(&LastSaveTime);
char filename[24];
strftime(filename,24,"%Y%m%d%H%M",localtime(&LastSaveTime));
cerr<<"current"<<filename<<" ="<<LastSaveTime<<endl;客户端连接时间为2002.06.07 12:20,且客户端一连接上便开始发送数据,输出结果为
connect200206071220 =1023423605
current200206071220 =1023481208
为什么两次的LastSaveTime(time_t型变量)值不同,但格式化的字符串确是正确的???
1023481208-1023423605=57603 秒,大概16小时。
我试过几次,差值都在57601--57630浮动。很是不解?
int nYear = tm.GetYear(); // 2002
int nMonth = tm.GetMonth(); // 6
int nDay = tm.GetDay(); // 7
int nHour = tm.GetHour(); // 12
int nMinute = tm.GetMinute(); // 20
int nSecond = tm.GetSecond(); // 5 CTime tm(1023481208);
int nYear = tm.GetYear(); // 2002
int nMonth = tm.GetMonth(); // 6
int nDay = tm.GetDay(); // 8
int nHour = tm.GetHour(); // 4
int nMinute = tm.GetMinute(); // 20
int nSecond = tm.GetSecond(); // 8是不是两台机器上的时间不一致,或者时区的设置不一致?