CString s("2001-8-31");
int nYear, nMonth, nDate, nHour, nMin, nSec;
sscanf(s, "%d-%d-%d %d:%d:%d", &nYear, &nMonth, &nDate, &nHour, &nMin, &nSec);
CTime t1(nYear, nMonth, nDate, nHour, nMin, nSec);
CTimeSpan ts(1,0,0,0);//一天 增加兩天(2,0,0,0)
t1+= ts;//t1 = 2001-9-1
CString strDay;
strDay.Format("%d-%d-%d",t1.GetYear(),t1.GetMonth(),t1.GetDay() );
AfxMessageBox(strDay);//2001-9-1
CString s("2001-8-31");
CString s1(" 00:00:00");
s = s+s1;
int nYear, nMonth, nDate, nHour, nMin, nSec;
sscanf(s, "%d-%d-%d %d:%d:%d", &nYear, &nMonth, &nDate, &nHour, &nMin, &nSec);
CTime t1(nYear, nMonth, nDate, nHour, nMin, nSec);
CTimeSpan ts(1,0,0,0);//一天
t1+= ts;//t1 = 2001-9-1
CString strDay;
strDay.Format("%d-%d-%d",t1.GetYear(),t1.GetMonth(),t1.GetDay() );
s = strDay;
AfxMessageBox(s);//2001-9-1
//下面的可以把天數和月份小與10的前面加0 比如2001-9-8 ------->2001-09-08
if(t1.GetMonth() < 10 && t1.GetDay() < 10)
{
strDay.Format("%d-0%d-0%d",t1.GetYear(),t1.GetMonth(),t1.GetDay());
}
else if(t1.GetMonth() < 10)
{
strDay.Format("%d-0%d-%d",t1.GetYear(),t1.GetMonth(),t1.GetDay());
}
else
{
strDay.Format("%d-%d-0%d",t1.GetYear(),t1.GetMonth(),t1.GetDay());
}