问题如上所述,下举一例:如截止日期是20051229,月数是12个月,现要倒推回去得到如此的时间段:
起始日期 截至日期
20051130 -- 20051229
20051030 -- 20051129
20050930 -- 20051029
...............
即求函数 MyFunction(int nMonths,CTIME EndDate),函数返回如上分解的时间段[可能是一个二维整数数组或是其它}?谢谢,让大侠与高手们辛若哪?!
起始日期 截至日期
20051130 -- 20051229
20051030 -- 20051129
20050930 -- 20051029
...............
即求函数 MyFunction(int nMonths,CTIME EndDate),函数返回如上分解的时间段[可能是一个二维整数数组或是其它}?谢谢,让大侠与高手们辛若哪?!
解决方案 »
- 大家说说更倾向于哪种配置风格——微软的VS和IBM的Eclipse
- 请问这个错误怎么解决?
- WSAGetLastError()的返回值表示"内存锁定"的宏是什么?
- 忽然被一个listctrl的小问题搞迷糊了。
- 帮我看看问题在哪里?立马给粉
- 编译错误
- Wuxuehui(Exception)和jiangsheng(蒋晟)请进(关于MSHTML Editor)
- 怎样在vc下设置unicode debug目标(运行在98下)
- 为什么我创建一个线程占用CPU总是%100 ? 显示菜单都变慢了
- 菜鸟取经,请大虾们莫保守!
- listbox怎样实现分栏,上面有属性列标题
- 有關Bounds Checker的問題,請教一下,散分了。
还得把年、月换成天。
#include <time.h>
#include <iostream>
using namespace std;BOOL MonthPeriod(int nMonthCount,CTime EndDate, CStringArray &sa)
{
int nYear, nTmpYear;
int nMonth, nTmpMonth;
int nDay, nTmpDay;
CString sTmp; time_t tm1;
tm1 = time(NULL); nYear = EndDate.GetYear();
nMonth = EndDate.GetMonth();
nDay = EndDate.GetDay();
int nOldMonth = nMonth;
int nCount = 0; struct tm tmSampleData = { 0, 0, 1, nDay, nMonth - 1, nYear - 1900 }; while(nCount < nMonthCount)
{
tmSampleData.tm_mday--;
time_t tData = mktime(&tmSampleData);
char szData[20] = { 0 };
strftime(szData, 20, "%Y-%m-%d", localtime(&tData));
sscanf(szData, "%4d-%02d-%02d", &nTmpYear, &nTmpMonth, &nTmpDay);
if(nTmpMonth != nOldMonth)
{
nCount++;
nOldMonth = nTmpMonth;
sTmp.Format("%s", szData);
sa.Add(sTmp);
}
}
return TRUE;
}void main(void)
{
printf("\n TIME PERIOD TEST NOW\n");
CStringArray sa;
MonthPeriod(12, CTime(2005, 7, 30, 18, 30, 20), sa);
for(int j = 0; j < sa.GetSize(); j++)
cout << sa[j].operator LPCTSTR() << endl; getchar();
printf("\n");
}程序输出: TIME PERIOD TEST NOW
2005-06-30
2005-05-31
2005-04-30
2005-03-31
2005-02-28
2005-01-31
2004-12-31
2004-11-30
2004-10-31
2004-09-30
2004-08-31
2004-07-31