?? date1.cpp
字號(hào):
#include "Date1.h"#include <stdio.h>#include <string.h>#include <stdlib.h>CDate1::CDate1(const char* szYYMMDDHH24MI1, const char* szYYMMDDHH24MI2){ memset(m_szDate1, 0, sizeof(m_szDate1)); memset(m_szDate2, 0, sizeof(m_szDate2)); strcpy(m_szDate1, szYYMMDDHH24MI1); strcpy(m_szDate2, szYYMMDDHH24MI2); m_nList.clear();}CDate1::~CDate1(){ m_nList.clear();}int CDate1::GetCount(){ return m_nList.size();}bool CDate1::isLeap(int year){ int isLeap = 0; if((year % 4) == 0) { isLeap = 1; if((year % 100) == 0) { isLeap = 0; if((year % 400) == 0) { isLeap = 1; } } } return isLeap; }string CDate1::GetAt(int i){ return m_nList.at(i);//.c_str();}void CDate1::Add(const char* sz){ m_nList.push_back(sz);}static int MM1[12] = {31,28,31,30,31,30,31,31,30,31,30,31};//leapstatic int MM2[12] = {31,29,31,30,31,30,31,31,30,31,30,31};bool CDate1::Calculate(){ m_nList.clear(); // //Add(); char szIn[50+1]; int flag; int nBegin[50],nEnd[50],nDiff[50]; //convert date value to relative int type if(!strcmp(m_szDate1,"")) return 0; Add(m_szDate1); if(!strcmp(m_szDate1,m_szDate2)) return 1; if(!strcmp(m_szDate2,"")) return 0; for(int i=0;i<5;i++) { nBegin[i]=(m_szDate1[2*i]-48)*10+(m_szDate1[2*i+1]-48); nEnd[i]=(m_szDate2[2*i]-48)*10+(m_szDate2[2*i+1]-48); } // for(;;) { if((nBegin[4]+=30)==60) { nBegin[4]=0; nBegin[3]+=1; }; if (nBegin[3]==24) { nBegin[3]=0; flag=isLeap(2000+nBegin[0]); // printf("flag=[%d]",flag); if (flag) { nBegin[2]+=1; if(nBegin[2]>MM2[nBegin[1]-1]) { nBegin[2]=1; if ((nBegin[1]+=1)>12) { nBegin[0]+=1; } } } else { if((nBegin[2]+=1)>MM1[nBegin[1]-1]) { nBegin[2]=1; if ((nBegin[1]+=1)>12) { nBegin[0]+=1; } } } } snprintf(szIn,50,"%02d%02d%02d%02d%02d",nBegin[0],nBegin[1],nBegin[2],nBegin[3],nBegin[4]); Add(szIn); if(strcmp(szIn,m_szDate2)==0) return true; } return true;}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -