C++返回相对于某个日期的第几周

#include <iostream>
#include <boost/date_time.hpp>
using namespace std;
using namespace boost::gregorian;
//返回dtLastDatetime相对于dtCurDatetime日期的第几周
int GetOrderWeek(const date &dtLastDatetime, const date &dtCurDatetime);

 

void main()
{

 int order = 100;
 order += 200;
 date myCurDatetime =  from_undelimited_string("20130603122520");
 date myLastDatetime = from_undelimited_string("20130602124255");

    int nResult = GetOrderWeek(myLastDatetime, myCurDatetime);
 cout << nResult << endl;
// cout << order << endl; 

 int wait;
 cin >> wait;
}

 


int GetOrderWeek(const date &dtLastDatetime, const date &dtCurDatetime)
{
 int ndtLastDatetimeDays = 0;
 int ndtCurDatetimeDays = 0;
 ndtLastDatetimeDays = dtLastDatetime.day_of_year();
 ndtCurDatetimeDays = dtCurDatetime.day_of_year();

 int nCurWeek = dtCurDatetime.day_of_week(); //表示当前交易记录平仓日期是星期几


 int increase =0;                            //表示增量,用于计算dtLastDatetime相对于dtCurDatetime的第几个星期
 if (nCurWeek = 0)                           //nCurWeek =0, 表示当前为星期日
 {
  increase = 7 - 7;
 }
 else
 {

  increase = 7 - nCurWeek;
 }

 int nGapName = 0;                              //表示dtCurDatetime与dtLastDatetime相隔多少天
 nGapName = ndtCurDatetimeDays - ndtLastDatetimeDays;

 int orderWeek = 0;                         //表示dtLastDatetime 相对于dtCurDatetime的第几周
 orderWeek = (nGapName + increase) / 7;
 return orderWeek;
}

 

posted @ 2013-06-22 09:31  Predator  阅读(1260)  评论(0编辑  收藏  举报