编者:李国帅


时间:2012-8-20 8:29:48

 

问题相关:

在使用com的时候,经常会使用到时间函数,那就需要考虑使用那个时间库了,我们在开发中可能会用到别人的库和代码,那么也需要考虑兼容的问题。于是就需要考虑下面这个问题:

一个文件中尽量使用一种库函数,不然可能导致函数库冲突。

使用atltime库:

 

#include <atltime.h>//这个库中的new函数和其他的定义冲突。

//CTime Now = CTime::GetCurrentTime();
//tmData = Now.GetTime();
CTime Now = CTime::GetCurrentTime();
nYear = Now.GetYear();
nMonth = Now.GetMonth();
nDay = Now.GetDay();
_stscanf_s(strDate, _T("%02d:%02d:%02d"), &nHour, &nMinute, &nSecond);
CTime tBegin(nYear, nMonth, nDay, nHour, nMinute, nSecond);
tmData = tBegin.GetTime();

 

使用标准库:

#include <time.h>
time_t now;
time(&now);
struct tm localt;
localtime_s(&localt,&now);

_stscanf_s(strDate, _T("%02d:%02d:%02d"), &nHour, &nMinute, &nSecond);
localt.tm_hour = nHour;
localt.tm_min = nMinute;
localt.tm_sec = nSecond;

tmData = mktime(&localt);