//字符格式转化为时间,真:加一天;假:减一天
//字符格式转化为时间
CString CGrossProfitRatioReportDlg::StrToDate(CString strTime,bool bAddOrPlus)
{
CString str(strTime);
int year,month,day,hour,minite,second;
sscanf(str,"%d-%d-%d %d:%d:%d",&year,&month,&day,&hour,&minite,&second);
COleDateTime time(year,month,day,hour,minite,second);
COleDateTimeSpan Oneday(1);//一天时差
if (bAddOrPlus)
{
time += Oneday;//第二天了
}
else
{
time -= Oneday;//前一天了
}
CString strDate;
strDate=time.Format("%Y-%m-%d");
return strDate;
}
2.
//字符格式转化为时间
CString CGrossProfitRatioReportDlg::StrToDate(CString strTime,bool bAddOrPlus)
{
CString str(strTime);
int year,month,day,hour,minite,second;
sscanf(str,"%d-%d-%d %d:%d:%d",&year,&month,&day,&hour,&minite,&second);
COleDateTime time(year,month,day,hour,minite,second);
COleDateTimeSpan Oneday(1);//一天时差
if (bAddOrPlus)
{
time += Oneday;//第二天了
}
else
{
time -= Oneday;//前一天了
}
CString strDate;
strDate=time.Format("%Y-%m-%d");
return strDate;
}
2.
CString str("2005-8-25 14:00:35");
int nYear, nMonth, nDay, nHour, nMinite, nSecond;
sscanf(str, "%d-%d-%d %d:%d:%d",
&nYear, &nMonth, &nDay, &nHour, &nMinite, &nSecond);
CTime time(nYear, nMonth, nDay, nHour, nMinite, nSecond);Top
3.
直接用COleDateTime,CTime的
功能
COleDateTime都有.
COleDateTime oleTime1 = COleDateTime::GetCurrentTime();
COleDateTime oleTime2;
CString str= "2005-01-01 12:12:12"
oleTime2.ParseDateTime(str);
if (oleTime2 > oleTime)//COleDateTime重载了比较操作符