clear all
close all
clc
a=menu('萬年曆','建月曆請按此','查某年某月某日為星期幾請按此');
if a==1
y=inputdlg({'請輸入你要建那一年的月曆'});
y=str2num(char(y));
m=menu('請選擇你要建那一月的月曆','1','2','3','4','5','6','7','8','9','10','11','12');
ans=[];
if rem(y,100)==0 & rem(y,400)==0 rem(y,4)==0
d1=[31 29 31 30 31 30 31 31 30 31 30 31];
else
d1=[31 28 31 30 31 30 31 31 30 31 30 31];
end
s=y-1;c=d1(1:(m-1));
for k=1:d1(m)
c1=sum(c)+k;
ss=s+fix(s/4)-fix(s/100)+fix(s/400)+c1;
ans(k)=rem(ss,7);
end
ans(ans==0)=7;
pp=ans(1);ans1=[];
k1=0;
for n=1:6;
for m1=pp:7
ans1(n,m1)=k1;
k1=k1+1;
end
pp=1;
end
ans1(ans1>d1(m))=0;
s=xlswrite('月曆.xls',{[y],' 年',[m],' 月'});
s=xlswrite('月曆.xls',{'星期日','星期一','星期二','星期三','星期四','星期五','星期六'},...
'a2:g2');
s=xlswrite('月曆.xls',ans1,'a3:g8');
as=sprintf(['你的月曆已經建好了\n\n','請到你的儲存路徑下打開[月曆.xls]這個檔\n\n']);
msgbox(as)
else
y=inputdlg({'請輸入你要查詢那一年'});
y=str2num(char(y));
m=inputdlg({'請輸入你要查詢那一月'});
m=str2num(char(m));
k=inputdlg({'請輸入你要查詢那一日'});
k=str2num(char(k));
ans=[];
if rem(y,100)==0 & rem(y,400)==0 rem(y,4)==0
d1=[31 29 31 30 31 30 31 31 30 31 30 31];
else
d1=[31 28 31 30 31 30 31 31 30 31 30 31];
end
s=y-1;
c=d1(1:(m-1));
c1=sum(c)+k;
ss=s+fix(s/4)-fix(s/100)+fix(s/400)+c1;
dd=rem(ss,7)+1;
di={'日','一','二','三','四','五','六'};
msgbox(['你查詢的',num2str(y),'年',num2str(m),'月',num2str(k),'日','是星期',di(dd)])
end
結果
沒有留言:
張貼留言