日期計算c

來源:互聯網
上載者:User

標籤:日期計算

沒有用到類

而且不能計算到公元前

#include <stdio.h>#include <stdlib.h>int Year(int year){if(year%4==0&&year%100!=0||year%400==0)return 1;else return 0;}     void daytoyear(int v[]){int day=0;int i=0,j=0,k=0;int count=0;int star[13]={0,1,32,60,91,121,152,182,213,244,274,304,334};//0-6 int chazhi=0; for(i=1;i<v[0];i++)   {  if(Year(i)) count+=366;else count+=365;} if(Year(v[0])){for(j=3;j<12;j++)star[j]++; }   count=count+star[v[1]]+v[2]-1; if(Year(v[0])){for(j=3;j<12;j++)star[j]--; }printf(" %d年  %d月%d 日 %d  天后的時間如下\n",v[0],v[1],v[2],v[3]);       for(i=1;day<(count+v[3]);i++)       {  if(Year(i))day+=366;else day+=365;   }          if(Year(i)){ day-=366; for(j=3;j<12;j++)star[j]++;} else day-=365;     chazhi=count+v[3]-day;           for(j=1;j<13;j++){if(star[j]<chazhi)k++;}        printf(" %d年  %d月%d 日 \n",i-1,k,chazhi-star[k]);}void daytoyear1(int v[]){int day=0;int i=0,j=0,k=0;int count=0;int star[13]={0,1,32,60,91,121,152,182,213,244,274,304,334};//0-6 int chazhi=0; for(i=1;i<v[0];i++)   {  if(Year(i)) count+=366;else count+=365;} if(Year(v[0])){for(j=3;j<12;j++)star[j]++; }   count=count+star[v[1]]+v[2]-1; if(Year(v[0])){for(j=3;j<12;j++)star[j]--; }printf(" %d年  %d月%d 日 %d  天前的時間如下\n",v[0],v[1],v[2], v[3]);       for(i=1;day<(count-v[3]+1);i++)       {  if(Year(i))day+=366;else day+=365;   }          if(Year(i)){ day-=366; for(j=3;j<12;j++)star[j]++;} else day-=365;     chazhi=count-v[3]-day;           for(j=1;j<13;j++){if(star[j]<chazhi)k++;}        printf(" %d年  %d月%d 日 \n",i-1,k+1,chazhi-star[k]+1);}void main(){int x[4]={1,1,1,400};//2-2-4int y[4]={2,2,4,399}; daytoyear(x);daytoyear1(y);  }

存在1天的偏差   然後這裡不同的人有不同的理解1號和3號間的天數有2天或3天,看自己怎樣理解

日期計算c

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.