CString time1 ="2007-06-13 10:10:10";
CString time2 ="2007-06-13 20:10:10";
CTime tNow = CTime::GetCurrentTime ();
CString szMsgBuffer = tNow.Format ("%Y-%m-%d %H:%M:%S");
if(szMsgBuffer > time1 && time2 < szMsgBuffer)
{
AfxMessageBox("ye"); }
else{AfxMessageBox("no");}
CString time2 ="2007-06-13 20:10:10";
CTime tNow = CTime::GetCurrentTime ();
CString szMsgBuffer = tNow.Format ("%Y-%m-%d %H:%M:%S");
if(szMsgBuffer > time1 && time2 < szMsgBuffer)
{
AfxMessageBox("ye"); }
else{AfxMessageBox("no");}
2. Covert SYSTEMTIME to FILETIME.
3. Compare times using FILETIME.//CString to SYSTEMTIME
CString str = "2007-06-13 10:10:10";
COleVariant vt(str);
vt.ChangeType(VT_DATE);
COleDateTime odt = vt;
SYSTEMTIME st;
VariantTimeToSystemTime(odt, &st);
//CTime to SYSTEMTIME
CTime time(CTime::GetCurrentTime());
SYSTEMTIME st;
time.GetAsSystemTime(st);
//SYSTEMTIME to FILETIME
SystemTimeToFileTime
CString time1 ="2007-06-13 10:10:10";
CString time2 ="2007-06-13 20:10:10";
time2字符串肯定比time1字符串大。
CString szMsgBuffer = tNow.Format ("%Y-%m-%d %H:%M:%S");
得到的字符串和time1类型不一样
int a=strcmp(tiem1,tiem2);
if(a>0)
{
AfxMessageBox("ye"); }
else{
AfxMessageBox("no");}
上面的两种字符串比较是否安全呢!!
const FILETIME* lpFileTime1,
const FILETIME* lpFileTime2
);
就用Ctime 直接比较好了,何必用CString来比较