日期处理c++

计算日期之间的天数

#include<iostream>
#include<cstdio>
#include   <stdlib.h>
#include <stack>
#include <string>
#include<queue>
#include<math.h>
//#include<vector>
using namespace std;


bool is_leep(int year)
{
    return ((year%4==0 && year%100==0)||(year%400==0))? 1:0;
}



int main()
{
    /*
    int a;
    int b;
    cin>>a;
    cin>>b;
    */
    int mounth[12][2]={
        {31,31},{28,29},{31,31},{30,30},{31,31},{30,30},{31,31},{31,31},{30,30},{31,31},{30,30},{31,31}
    };
    int y1,m1,d1,time1;
    int y2,m2,d2,time2;
    int exc=0;
    cin>>time1;
    cin>>time2;
        if(time1>time2)//---确定t2大于t1
        {
            exc=time1;
            time1=time2;
            time2=exc;
        }
        
    
    
    y1=time1/10000;
    m1=(time1-(y1*10000))/100;
    d1=time1-(y1*10000)-(m1*100);
    
    y2=time2/10000;
    m2=(time2-(y2*10000))/100;
    d2=time2-(y2*10000)-(m2*100);
    
    cout<<y1<<","<<m1<<","<<d1<<endl;
    cout<<y2<<","<<m2<<","<<d2<<endl;
    
    //===========第一个日期没有达到第二个就继续循环
    
    int count1=0;
    
     
    do{
        d1++;
        
            if(d1==mounth[m1-1][is_leep(y1)]+1){
                m1++;
                d1=1;
                
            }
            if(m1==13)
            {
                y1++;
                m1=1;
            }
            
        
        
        count1++;
        
    }while(y1<y2||m1<m2||d1<d2);
     
    
    /*
    while(y1<y2||m1<m2||d1<d2)
        
    {
        d1++;
        
        if(d1==mounth[m1][is_leep(y1)]+1){
            m1++;
            d1=1;
            
        }
        if(m1==13)
        {
            y1++;
            m1=1;
        }
        
        
        
        count1++;
    }
    */
    cout<<count1+1<<endl;
    
    //cout<<is_leep(2019)<<endl;
    
    
    return 0;
}

/*
 20141015
 20141011
 */


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值