在这里,我们将用Microsoft最新推出的Net Framework-C#来创建一个万年历(文中所用的程序是一个带万年历功能的日记本)。
首先打开Microsoft的VSNET(Visual StudioNET)创建一个新项目。选择Visual C#项目,在模板中选择Windows应用程序,按“确定”后,一个Windows窗体就建好了。这就是我们平常说的Win Form啦。
下面先在Visual C#界面下把日记本的样式设计出来。需要两个万年历控件,一个用来显示、添加、编辑日记内容的“丰富的文本框”(richtextbox控件),还有一个用来添加和修改日记的按钮(button控件)。richtextbox控件和button控件都能很容易地在工具箱中找到,不用多说添加上去就可以了,关键在于万年历,我们不必自己去编写一个万年历,微软已经为我们写好了。要做的就是把它拿出来按照正确的方法使用。首先我来说说如何调用这个万年历。它是Microsoft公司VSNET产品附送的一个控件。我们在VSNET窗口下点击“项目”下拉菜单,然后选择“添加/引用”就会d出一个用于引用控件的窗体,此窗体包含三个标签,即“Net”、“COM”、“项目”。我们要用的日历控件就包含在其中的“COM”里面。点击它,然后在硬盘一阵狂响之后,会发现多出了好多控件。找到控件Microsoft Calendar Control 90。
选中这个控件,点击右边的选择按钮,控件的名称会出现在下边“选定的组件”窗口中,这时候选择下边的“确定”按钮,选定的控件便添加到你所创建的项目当中了。你可以在你的“工具箱”当中找到一个名字叫做MonthCalendar的控件和一个叫做DateTimePicker的控件,这两个控件便是我们刚才引用来的。在这里我们要用到的是第一个MonthCalendar,选择MonthCalendar控件并在窗体上划出它的轮廓。看,一个万年历便展示在我们面前了。
但是只我们能看还不行,为了能察看或者修改以前的日记还需要让程序知道我们在这个控件选择的日期是哪一天,这样才能告诉数据库,我们要调用哪一天的日记。为了方便暂时用richtextbox做显示当前日期的容器。
现在来研究一下如何让richtextbox显示MounthCalendar所选择的日期。双击MounthCalendar控件,会跳转到代码界面,并且得到一个系统为我们自动创建的事件。这个事件就是日期选择事件,是MounthCalendar控件的默认事件。
private void monthCalendar_DateChanged(object sender,
SystemWindowsFormsDateRangeEventArgs e)
{
file://事件被触发后所执行的代码
}
利用这个事件我们便可以让程序知道,用户何时重新选择了一个日期。但是如果想要让程序知道用户所选择的日期是哪一天并且让程序将这一天的日期显示在richtextbox上,我们还有一个问题,那就是如何读取用户所选择的日期,这就要用到下面这个属性
monthCalendarSelectionRangeStartToShortDateString() 。
这个属性的值便是用户所选择的日期。现在事件定义了,属性也找到了,下边让我们来看一下如何把日期显示在richtextbox容器内。
添加这段代码到事件中
richTextBoxText=monthCalendarSelectionRangeStartToShortDateString();
运行一下。当选择了一个日期后,这个日期便会显示在richtextbox内了。
这样一个万年历就完成了。从这个例子可以看到,VSNET提供了非常丰富的控件库。朋友们在使用VSNET进行编程的时候,不要浪费这些资源,它们会帮助我们节省好多宝贵的时间和精力。
//C51写的公历转农历和星期
#define uchar unsigned char
#define uint unsigned int
#include <intrinsh>
/
公历年对应的农历数据,每年三字节,
格式第一字节BIT7-4 位表示闰月月份,值为0 为无闰月,BIT3-0 对应农历第1-4 月的大小
第二字节BIT7-0 对应农历第5-12 月大小,第三字节BIT7 表示农历第13 个月大小
月份对应的位为1 表示本农历月大(30 天),为0 表示小(29 天)
第三字节BIT6-5 表示春节的公历月份,BIT4-0 表示春节的公历日期
/
code uchar year_code[597] = {
0x04,0xAe,0x53, //1901 0
0x0A,0x57,0x48, //1902 3
0x55,0x26,0xBd, //1903 6
0x0d,0x26,0x50, //1904 9
0x0d,0x95,0x44, //1905 12
0x46,0xAA,0xB9, //1906 15
0x05,0x6A,0x4d, //1907 18
0x09,0xAd,0x42, //1908 21
0x24,0xAe,0xB6, //1909
0x04,0xAe,0x4A, //1910
0x6A,0x4d,0xBe, //1911
0x0A,0x4d,0x52, //1912
0x0d,0x25,0x46, //1913
0x5d,0x52,0xBA, //1914
0x0B,0x54,0x4e, //1915
0x0d,0x6A,0x43, //1916
0x29,0x6d,0x37, //1917
0x09,0x5B,0x4B, //1918
0x74,0x9B,0xC1, //1919
0x04,0x97,0x54, //1920
0x0A,0x4B,0x48, //1921
0x5B,0x25,0xBC, //1922
0x06,0xA5,0x50, //1923
0x06,0xd4,0x45, //1924
0x4A,0xdA,0xB8, //1925
0x02,0xB6,0x4d, //1926
0x09,0x57,0x42, //1927
0x24,0x97,0xB7, //1928
0x04,0x97,0x4A, //1929
0x66,0x4B,0x3e, //1930
0x0d,0x4A,0x51, //1931
0x0e,0xA5,0x46, //1932
0x56,0xd4,0xBA, //1933
0x05,0xAd,0x4e, //1934
0x02,0xB6,0x44, //1935
0x39,0x37,0x38, //1936
0x09,0x2e,0x4B, //1937
0x7C,0x96,0xBf, //1938
0x0C,0x95,0x53, //1939
0x0d,0x4A,0x48, //1940
0x6d,0xA5,0x3B, //1941
0x0B,0x55,0x4f, //1942
0x05,0x6A,0x45, //1943
0x4A,0xAd,0xB9, //1944
0x02,0x5d,0x4d, //1945
0x09,0x2d,0x42, //1946
0x2C,0x95,0xB6, //1947
0x0A,0x95,0x4A, //1948
0x7B,0x4A,0xBd, //1949
0x06,0xCA,0x51, //1950
0x0B,0x55,0x46, //1951
0x55,0x5A,0xBB, //1952
0x04,0xdA,0x4e, //1953
0x0A,0x5B,0x43, //1954
0x35,0x2B,0xB8, //1955
0x05,0x2B,0x4C, //1956
0x8A,0x95,0x3f, //1957
0x0e,0x95,0x52, //1958
0x06,0xAA,0x48, //1959
0x7A,0xd5,0x3C, //1960
0x0A,0xB5,0x4f, //1961
0x04,0xB6,0x45, //1962
0x4A,0x57,0x39, //1963
0x0A,0x57,0x4d, //1964
0x05,0x26,0x42, //1965
0x3e,0x93,0x35, //1966
0x0d,0x95,0x49, //1967
0x75,0xAA,0xBe, //1968
0x05,0x6A,0x51, //1969
0x09,0x6d,0x46, //1970
0x54,0xAe,0xBB, //1971
0x04,0xAd,0x4f, //1972
0x0A,0x4d,0x43, //1973
0x4d,0x26,0xB7, //1974
0x0d,0x25,0x4B, //1975
0x8d,0x52,0xBf, //1976
0x0B,0x54,0x52, //1977
0x0B,0x6A,0x47, //1978
0x69,0x6d,0x3C, //1979
0x09,0x5B,0x50, //1980
0x04,0x9B,0x45, //1981
0x4A,0x4B,0xB9, //1982
0x0A,0x4B,0x4d, //1983
0xAB,0x25,0xC2, //1984
0x06,0xA5,0x54, //1985
0x06,0xd4,0x49, //1986
0x6A,0xdA,0x3d, //1987
0x0A,0xB6,0x51, //1988
0x09,0x37,0x46, //1989
0x54,0x97,0xBB, //1990
0x04,0x97,0x4f, //1991
0x06,0x4B,0x44, //1992
0x36,0xA5,0x37, //1993
0x0e,0xA5,0x4A, //1994
0x86,0xB2,0xBf, //1995
0x05,0xAC,0x53, //1996
0x0A,0xB6,0x47, //1997
0x59,0x36,0xBC, //1998
0x09,0x2e,0x50, //1999 294
0x0C,0x96,0x45, //2000 297
0x4d,0x4A,0xB8, //2001
0x0d,0x4A,0x4C, //2002
0x0d,0xA5,0x41, //2003
0x25,0xAA,0xB6, //2004
0x05,0x6A,0x49, //2005
0x7A,0xAd,0xBd, //2006
0x02,0x5d,0x52, //2007
0x09,0x2d,0x47, //2008
0x5C,0x95,0xBA, //2009
0x0A,0x95,0x4e, //2010
0x0B,0x4A,0x43, //2011
0x4B,0x55,0x37, //2012
0x0A,0xd5,0x4A, //2013
0x95,0x5A,0xBf, //2014
0x04,0xBA,0x53, //2015
0x0A,0x5B,0x48, //2016
0x65,0x2B,0xBC, //2017
0x05,0x2B,0x50, //2018
0x0A,0x93,0x45, //2019
0x47,0x4A,0xB9, //2020
0x06,0xAA,0x4C, //2021
0x0A,0xd5,0x41, //2022
0x24,0xdA,0xB6, //2023
0x04,0xB6,0x4A, //2024
0x69,0x57,0x3d, //2025
0x0A,0x4e,0x51, //2026
0x0d,0x26,0x46, //2027
0x5e,0x93,0x3A, //2028
0x0d,0x53,0x4d, //2029
0x05,0xAA,0x43, //2030
0x36,0xB5,0x37, //2031
0x09,0x6d,0x4B, //2032
0xB4,0xAe,0xBf, //2033
0x04,0xAd,0x53, //2034
0x0A,0x4d,0x48, //2035
0x6d,0x25,0xBC, //2036
0x0d,0x25,0x4f, //2037
0x0d,0x52,0x44, //2038
0x5d,0xAA,0x38, //2039
0x0B,0x5A,0x4C, //2040
0x05,0x6d,0x41, //2041
0x24,0xAd,0xB6, //2042
0x04,0x9B,0x4A, //2043
0x7A,0x4B,0xBe, //2044
0x0A,0x4B,0x51, //2045
0x0A,0xA5,0x46, //2046
0x5B,0x52,0xBA, //2047
0x06,0xd2,0x4e, //2048
0x0A,0xdA,0x42, //2049
0x35,0x5B,0x37, //2050
0x09,0x37,0x4B, //2051
0x84,0x97,0xC1, //2052
0x04,0x97,0x53, //2053
0x06,0x4B,0x48, //2054
0x66,0xA5,0x3C, //2055
0x0e,0xA5,0x4f, //2056
0x06,0xB2,0x44, //2057
0x4A,0xB6,0x38, //2058
0x0A,0xAe,0x4C, //2059
0x09,0x2e,0x42, //2060
0x3C,0x97,0x35, //2061
0x0C,0x96,0x49, //2062
0x7d,0x4A,0xBd, //2063
0x0d,0x4A,0x51, //2064
0x0d,0xA5,0x45, //2065
0x55,0xAA,0xBA, //2066
0x05,0x6A,0x4e, //2067
0x0A,0x6d,0x43, //2068
0x45,0x2e,0xB7, //2069
0x05,0x2d,0x4B, //2070
0x8A,0x95,0xBf, //2071
0x0A,0x95,0x53, //2072
0x0B,0x4A,0x47, //2073
0x6B,0x55,0x3B, //2074
0x0A,0xd5,0x4f, //2075
0x05,0x5A,0x45, //2076
0x4A,0x5d,0x38, //2077
0x0A,0x5B,0x4C, //2078
0x05,0x2B,0x42, //2079
0x3A,0x93,0xB6, //2080
0x06,0x93,0x49, //2081
0x77,0x29,0xBd, //2082
0x06,0xAA,0x51, //2083
0x0A,0xd5,0x46, //2084
0x54,0xdA,0xBA, //2085
0x04,0xB6,0x4e, //2086
0x0A,0x57,0x43, //2087
0x45,0x27,0x38, //2088
0x0d,0x26,0x4A, //2089
0x8e,0x93,0x3e, //2090
0x0d,0x52,0x52, //2091
0x0d,0xAA,0x47, //2092
0x66,0xB5,0x3B, //2093
0x05,0x6d,0x4f, //2094
0x04,0xAe,0x45, //2095
0x4A,0x4e,0xB9, //2096
0x0A,0x4d,0x4C, //2097
0x0d,0x15,0x41, //2098
0x2d,0x92,0xB5, //2099
};
///月份数据表
code uchar day_code1[9]={0x0,0x1f,0x3b,0x5a,0x78,0x97,0xb5,0xd4,0xf3};
code uint day_code2[3]={0x111,0x130,0x14e};
/
函数功能:输入BCD阳历数据,输出BCD阴历数据(只允许1901-2099年)
调用函数示例:Conversion(c_sun,year_sun,month_sun,day_sun)
如:计算2004年10月16日Conversion(0,0x4,0x10,0x16);
c_sun,year_sun,month_sun,day_sun均为BCD数据,c_sun为世纪标志位,c_sun=0为21世
纪,c_sun=1为19世纪
调用函数后,原有数据不变,读c_moon,year_moon,month_moon,day_moon得出阴历BCD数据
/
bit c_moon;
data uchar year_moon,month_moon,day_moon,week;
/子函数,用于读取数据表中农历月的大月或小月,如果该月为大返回1,为小返回0/
bit get_moon_day(uchar month_p,uint table_addr)
{
uchar temp;
switch (month_p)
{
case 1:{temp=year_code[table_addr]&0x08;
if (temp==0)return(0);else return(1);}
case 2:{temp=year_code[table_addr]&0x04;
if (temp==0)return(0);else return(1);}
case 3:{temp=year_code[table_addr]&0x02;
if (temp==0)return(0);else return(1);}
case 4:{temp=year_code[table_addr]&0x01;
if (temp==0)return(0);else return(1);}
case 5:{temp=year_code[table_addr+1]&0x80;
if (temp==0) return(0);else return(1);}
case 6:{temp=year_code[table_addr+1]&0x40;
if (temp==0)return(0);else return(1);}
case 7:{temp=year_code[table_addr+1]&0x20;
if (temp==0)return(0);else return(1);}
case 8:{temp=year_code[table_addr+1]&0x10;
if (temp==0)return(0);else return(1);}
case 9:{temp=year_code[table_addr+1]&0x08;
if (temp==0)return(0);else return(1);}
case 10:{temp=year_code[table_addr+1]&0x04;
if (temp==0)return(0);else return(1);}
case 11:{temp=year_code[table_addr+1]&0x02;
if (temp==0)return(0);else return(1);}
case 12:{temp=year_code[table_addr+1]&0x01;
if (temp==0)return(0);else return(1);}
case 13:{temp=year_code[table_addr+2]&0x80;
if (temp==0)return(0);else return(1);}
}
}
/
函数功能:输入BCD阳历数据,输出BCD阴历数据(只允许1901-2099年)
调用函数示例:Conversion(c_sun,year_sun,month_sun,day_sun)
如:计算2004年10月16日Conversion(0,0x4,0x10,0x16);
c_sun,year_sun,month_sun,day_sun均为BCD数据,c_sun为世纪标志位,c_sun=0为21世
纪,c_sun=1为19世纪
调用函数后,原有数据不变,读c_moon,year_moon,month_moon,day_moon得出阴历BCD数据
/
void Conversion(bit c,uchar year,uchar month,uchar day)
{ //c=0 为21世纪,c=1 为19世纪 输入输出数据均为BCD数据
uchar temp1,temp2,temp3,month_p;
uint temp4,table_addr;
bit flag2,flag_y;
temp1=year/16; //BCD->hex 先把数据转换为十六进制
temp2=year%16;
year=temp110+temp2;
temp1=month/16;
temp2=month%16;
month=temp110+temp2;
temp1=day/16;
temp2=day%16;
day=temp110+temp2;
//定位数据表地址
if(c==0)
{
table_addr=(year+0x64-1)0x3;
}
else
{
table_addr=(year-1)0x3;
}
//定位数据表地址完成
//取当年春节所在的公历月份
temp1=year_code[table_addr+2]&0x60;
temp1=_cror_(temp1,5);
//取当年春节所在的公历月份完成
//取当年春节所在的公历日
temp2=year_code[table_addr+2]&0x1f;
//取当年春节所在的公历日完成
// 计算当年春年离当年元旦的天数,春节只会在公历1月或2月
if(temp1==0x1)
{
temp3=temp2-1;
}
else
{
temp3=temp2+0x1f-1;
}
// 计算当年春年离当年元旦的天数完成
//计算公历日离当年元旦的天数,为了减少运算,用了两个表
//day_code1[9],day_code2[3]
//如果公历月在九月或前,天数会少于0xff,用表day_code1[9],
//在九月后,天数大于0xff,用表day_code2[3]
//如输入公历日为8月10日,则公历日离元旦天数为day_code1[8-1]+10-1
//如输入公历日为11月10日,则公历日离元旦天数为day_code2[11-10]+10-1
if (month<10)
{
temp4=day_code1[month-1]+day-1;
}
else
{
temp4=day_code2[month-10]+day-1;
}
if ((month>0x2)&&(year%0x4==0))
{ //如果公历月大于2月并且该年的2月为闰月,天数加1
temp4+=1;
}
//计算公历日离当年元旦的天数完成
//判断公历日在春节前还是春节后
if (temp4>=temp3)
{ //公历日在春节后或就是春节当日使用下面代码进行运算
temp4-=temp3;
month=0x1;
month_p=0x1; //month_p为月份指向,公历日在春节前或就是春节当日month_p指向首月
flag2=get_moon_day(month_p,table_addr);
//检查该农历月为大小还是小月,大月返回1,小月返回0
flag_y=0;
if(flag2==0)temp1=0x1d; //小月29天
else temp1=0x1e; //大小30天
temp2=year_code[table_addr]&0xf0;
temp2=_cror_(temp2,4); //从数据表中取该年的闰月月份,如为0则该年无闰月
while(temp4>=temp1)
{
temp4-=temp1;
month_p+=1;
if(month==temp2)
{
flag_y=~flag_y;
if(flag_y==0)
month+=1;
}
else month+=1;
flag2=get_moon_day(month_p,table_addr);
if(flag2==0)temp1=0x1d;
else temp1=0x1e;
}
day=temp4+1;
}
else
{ //公历日在春节前使用下面代码进行运算
temp3-=temp4;
if (year==0x0)
{
year=0x63;c=1;
}
else year-=1;
table_addr-=0x3;
month=0xc;
temp2=year_code[table_addr]&0xf0;
temp2=_cror_(temp2,4);
if (temp2==0)
month_p=0xc;
else
month_p=0xd; //
/month_p为月份指向,如果当年有闰月,一年有十三个月,月指向13,无闰月指向12/
flag_y=0;
flag2=get_moon_day(month_p,table_addr);
if(flag2==0)temp1=0x1d;
else temp1=0x1e;
while(temp3>temp1)
{
temp3-=temp1;
month_p-=1;
if(flag_y==0)month-=1;
if(month==temp2)flag_y=~flag_y;
flag2=get_moon_day(month_p,table_addr);
if(flag2==0)temp1=0x1d;
else temp1=0x1e;
}
day=temp1-temp3+1;
}
c_moon=c; //HEX->BCD ,运算结束后,把数据转换为BCD数据
temp1=year/10;
temp1=_crol_(temp1,4);
temp2=year%10;
year_moon=temp1|temp2;
temp1=month/10;
temp1=_crol_(temp1,4);
temp2=month%10;
month_moon=temp1|temp2;
temp1=day/10;
temp1=_crol_(temp1,4);
temp2=day%10;
day_moon=temp1|temp2;
}
/函数功能:输入BCD阳历数据,输出BCD星期数据(只允许1901-2099年)
调用函数示例:Conver_week(c_sun,year_sun,month_sun,day_sun)
如:计算2004年10月16日Conversion(0,0x4,0x10,0x16);
c_sun,year_sun,month_sun,day_sun均为BCD数据,c_sun为世纪标志位,c_sun=0为21世
纪,c_sun=1为19世纪
调用函数后,原有数据不变,读week得出阴历BCD数据
/
code uchar table_week[12]={0,3,3,6,1,4,6,2,5,0,3,5}; //月修正数据表
/
算法:日期+年份+所过闰年数+月较正数之和除7 的余数就是星期但如果是在
闰年又不到3 月份上述之和要减一天再除7
星期数为0
/
void Conver_week(bit c,uchar year,uchar month,uchar day)
{//c=0 为21世纪,c=1 为19世纪 输入输出数据均为BCD数据
uchar temp1,temp2;
temp1=year/16; //BCD->hex 先把数据转换为十六进制
temp2=year%16;
year=temp110+temp2;
temp1=month/16;
temp2=month%16;
month=temp110+temp2;
temp1=day/16;
temp2=day%16;
day=temp110+temp2;
if (c==0){year+=0x64;} //如果为21世纪,年份数加100
temp1=year/0x4; //所过闰年数只算1900年之后的
temp2=year+temp1;
temp2=temp2%0x7; //为节省资源,先进行一次取余,避免数大于0xff,避免使用整型数据
temp2=temp2+day+table_week[month-1];
if (year%0x4==0&&month<3)temp2-=1;
week=temp2%0x7;
}
//test
uchar c_sun,year_sun,month_sun,day_sun;
void main()
{
c_sun=1;
year_sun=0x2;
month_sun=0x11;
day_sun=0x3;
Conver_week(c_sun,year_sun,month_sun,day_sun);
Conversion(c_sun,year_sun,month_sun,day_sun);
while(1);
}
#include<stdioh>
void PrintMonthCalender(int startDay,int days);/函数原型/
int GetWeekDay(int year,int month);/函数原型/
int GetMonthDays(int year,int month);/函数原型/
main()
{
int month,year;/定义变量/
printf("input the year and month<YYYY-MM>:");
scanf("%d-%d",&year,&month);/读入变量/
printf("\t\t\t%d-%d\n",year,month);
printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");/打印日历表头/
PrintMonthCalender(GetWeekDay(year,month),GetMonthDays(year,month));/调用函数子程序,打印出某年某月日历/
return 0;
}
/定义打印日历子程序/
void PrintMonthCalender(int startDay,int days)
{
int k=0,n=1;
while(k<startDay)
{
printf(" \t");
k++;
}
if(k==startDay&&k!=6)
{
printf("%d\t",n);
k++;
n++;
}
else if(k==startDay&&k==6)
{
printf("%d\n",n);
k++;
n++;
}
while(n<days)
{
if(k%7==6)
{
printf("%d\n",n);
k++;
n++;
}
else
{
printf("%d\t",n);
k++;
n++;
}
}
if(n=days)
{
printf("%d\n",n);
n++;
}
}
/定义求某月一号为周几子程序/
int GetWeekDay(int year,int month)
{
int GetMonthDays(int year,int month);
int n,WeekDay,days;
days=(year-1)365+(year-1)/400+(year-1)/4-(year-1)/100;
for(n=1;n<month;++n)
days=days+GetMonthDays(year,n);
WeekDay=(days+1)%7;
return WeekDay;
}
/定义求某年某月的天数子程序/
int GetMonthDays(int year,int month)
{
int MonthDays;
if((year%4==0&&year%100!=0)||year%400==0)
{
if(month==4||month==6||month==9||month==11)
MonthDays=30;
else if(month==2)
MonthDays=29;
else
MonthDays=31;
}
else
{
if(month==4||month==6||month==9||month==11)
MonthDays=30;
else if(month==2)
MonthDays=28;
else
MonthDays=31;
}
return MonthDays;
}
#include <stdioh> %头文件
char MonthDay[]={31,28,31,30,31,30,31,31,30,31,30,31}; %每月天数数组
char MonthDayLeap[]={31,29,31,30,31,30,31,31,30,31,30,31}; %闰年每月天数
char WeekDayName[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
/获取按键值/
char getkey()
{
char c,s[10];
scanf("%s",s); %输入想用功能的序号
c=s[0];
return c; %返回输入的序号因为只有1·2·3·4所以只返回第一位
}
void printtab(int n)
{
while (n>0)
{
printf("\t"); 空格
n--;
}
}
/判断是否为闰年/
char isLeapYear(int y)
{
return((y%4 == 0 && y%100 != 0 || y%400 == 0)1:0); 年数取余4等于0且取余100不等于0或取余400等于0为真时返回1否则返回0
}
/计算星期几/
int WeekDay(int y,int m, int d) %y是年m是月d是日
{
int week;
if(m==1) m=13;
if(m==2) m=14;
week=(d+2m+3(m+1)/5+y+y/4-y/100+y/400)%7; 算星期的方程
return week;
}
/查询星期/
char queryweekday()
{
int y,m,d,week,c=0;
do
{
printf("请输入年月日(oooo oo oo)\n"); 输入时间
scanf("%d %d %d",&y,&m,&d);
week=WeekDay(y,m,d); 调用上一个函数计算星期
printf("%d年%d月%d日是星期%s,是否继续查询(Y/N)?",y,m,d,WeekDayName[week]); 输出
c=getkey(); 输入是否查询
}
while (c=='Y' || c=='y');
return c;
}
/显示月份/
void showmonth(int y,int m)
{
int d,dt,week;
week=WeekDay(y,m,1);
if (isLeapYear(y))
dt=MonthDayLeap[(m-1)%12]; 闰年算法
else
dt=MonthDay[(m-1)%12]; 平年算法
for (d=0;d<7;d++)
{
printf("\t%s",WeekDayName[d]);
}
printf("\n");
printtab(week);
for (d=1;d<=dt;d++)
{
printf("\t%6d",d);
if (WeekDay(y,m,d)==6)
printf("\n");
}
printf("\n");
}
/显示月份/
char printmonth()
{
int y,m,c=0;
do
{
printf("请输入年月(oooo oo)\n");
scanf("%d %d",&y,&m);
printtab(3);
printf("%d年\t%d月\n",y,m);
showmonth(y,m); 调用函数计算月份
printf("是否继续查询(Y/N)?");
c=getkey();
}
while (c=='Y' || c=='y');
return c;
}
/显示年份/
char printyear()
{
int y,m,c=0;
do
{
printf("请输入年份(oooo)\n");
scanf("%d",&y);
printtab(3);
printf("%d年年历\n",y);
for (m=1;m<=12;m++)
{
printtab(4);
printf("%d月\n",m);
showmonth(y,m);
}
printf("\n是否继续查询(Y/N)?");
c=getkey();
}
while (c=='Y' || c=='y');
return c;
}
/退出查询/
char toexit()
{
char c;
printf("是否要真的退出(Y/N)?");
c=getkey();
if(c=='Y' || c=='y')
return 1;
else
return 0;
}
/万年历主界面查询/
char getmenu()
{
printf("\n\n");
printf(" \t万年历查询程序\n");
printf("1\t根据日期查星期几\n");
printf("2\t显示某月的日历\n");
printf("3\t显示某年的日历\n");
printf("4\t退出\n");
printf("\n");
printf("请选择(1-4):");
return getkey();
}
int main(int argc, char argv[])
{
char doexit=0,choose;
do
{
/获取菜单/
choose=getmenu(); 调用函数得到所选的功能项
/分类处理/
switch (choose)
{
case '1':
queryweekday(); 星期
break;
case '2':
printmonth(); 月
break;
case '3':
printyear(); 年
break;
case '4':
doexit=toexit(); 退出
break;
default:
break;
}
}
while (!doexit);
return 0;
}
已经编译运行确认过。
#include <stdioh>
#include <stdlibh>
int leap(int); /判断是否为闰年/
int md(int m,int y); /返回本月的天数/
void prtweek(void); /输出表头/
int fw(int m,int y); /返回本月一号是星期几/
void prtmonth(int m); /输出月份表头/
int main(void)
{
int y,m,i,test,week;
printf("please import year of you want to select : ");
scanf("%d",&y);
for (m=1; m<=12; m++) {
test=1;
prtmonth(m);
prtweek();
week=fw(m,y);
if (week!=6)
for (i=0; i<=week; i++) {
putchar('\t');
test++;
}
for (i=1; i<=md(m,y); i++,test++) {
printf("%d\t",i);
if (test%7==0) {
putchar('\n');
}
}
putchar('\n');
system("pause");//暂停,以便观察输出
}
return 0;
}
int leap(int y)
{
return (y%4==0&&y%100||y%400==0)1:0;
}
int md(int m,int y)
{
int d;
switch (m) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:d=31;break;
case 4:
case 6:
case 9:
case 11:d=30;break;
case 2:d=leap(y)29:28;break;
}
return d;
}
void prtweek(void)
{
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n","Sun","Mon","Tue","Wed","Thur","Fri","Sat");
}
int fw(int m,int y)
{
int f;
if (m<3) {
m+=12;
y--;
}
f=(1+2m+3(m+1)/5+y+y/4-y/100+y/400)%7;
return f;
}
void prtmonth(int m)
{
switch (m) {
default:
case 1:puts("===January===");break;
case 2:puts("===February===");break;
case 3:puts("===March===");break;
case 4:puts("===April===");break;
case 5:puts("===May===");break;
case 6:puts("===June===");break;
case 7:puts("===July===");break;
case 8:puts("===August===");break;
case 9:puts("===September===");break;
case 10:puts("===October===");break;
case 11:puts("===November===");break;
case 12:puts("===December===");break;
}
}
提起万历年日历查询,大家都知道,有人问万年历每天怎么查询,另外,还有人想问万年历农历查询,你知道这是怎么回事?其实Java日历查询程序(万年历),下面就一起来看看万年历每天怎么查询,希望能够帮助到大家!
万历年日历查询
1、万历年日历查询:万年历每天怎么查询
掌心万年历是一款运行在PPC&SmartPhone上的式架构的万年历软件,包含年范围内的公农历查询、历史上的、黄道吉日、支持自定义公农历生日提醒。一款华人必备的软件。。
2、万历年日历查询:万年历农历查询
阴历十月初二,是天蝎座。万年农历查询。
3、万历年日历查询:Java日历查询程序(万年历)
花了半个小时写了一个望采纳给好评。
;万年历查询在线。
publicclassPrintCalendar{黄历查询。
/Mainmethod/万历38年日历农历八月初七日。
publicstaticvoidmain(String[]args){
Scannerinput=newScanner(Systemin);
//Prompttheusertoenteryear
“Enterfullyear(:”);万历34年是现在的哪一年。
intyear=inputnextInt();
//Prompttheusertoentermonth时辰万年历。
“:”);
intmonth=inputnextInt();
//Printcalendarforthemonthoftheyear
printMonth(year,month);/Printthecalendarforamonthinayear/
publicstaticvoidprintMonth(intyear,intmonth){万历己丑年是哪一年。
//Printtheheadingsofthecalendar万年历年号。
printMonthTitle(year,month);
//Printthebodyofthecalendar
printMonthBody(year,month);/Printthemonthtitle,/万历2年是哪一年。
publicstaticvoidprintMonthTitle(intyear,intmonth){万历表。
“”+getMonthName(month)
+””+year);明朝万历年距今多少年。
“—————————–“);
“SunMonTueWedThuFriSat”);/GettheEnglishnameforthemonth/
publicstaticStringgetMonthName(intmonth){
StringmonthName=””;
switch(month){
case1:monthName=”January”;break;
case2:monthName=”February”;break;
case3:monthName=”March”;break;
case4:monthName=”April”;break;万历年是什么时候。
case5:monthName=”May”;break;
case6:monthName=”June”;break;明朝万年历查询表。
case7:monthName=”July”;break;
case8:monthName=”August”;break;
case9:monthName=”September”;break;
:monthName=”October”;break;农历在线查询公历。
:monthName=”November”;break;
:monthName=”December”;returnmonthName;/Printmonthbody/
publicstaticvoidprintMonthBody(intyear,intmonth){
//Getstartdayoftheweekforthefirstdateinthemonth
Java日历查询程序(万年历)intstartDay=getStartDay(year,month);万历年代。
//Getnumberofdaysinthemonth
intnumberOfDaysInMonth=getNumberOfDaysInMonth(year,month);
//Padspacebeforethefirstdayofthemonth
inti=0;
for(i=0;i<startDay;i++)
“”);
for(i=1;i<=numberOfDaysInMonth;i++){
“%4d”,i);
if((i+startDay)%7==0)万年历生肖查询表。
;;/Getthestartdayofmonth/1/year/
publicstaticintgetStartDay(intyear,intmonth){
finalintSTART_DAY_FOR_JAN_1_=3;
//Gettotalnumberofdaysfrom1/1/tomonth/1/year
inttotalNumberOfDays=getTotalNumberOfDays(year,month);百年万年历。
//Returnthestartdayformonth/1/year
return(totalNumberOfDays+START_DAY_FOR_JAN_1_)%7;/GetthetotalnumberofdayssinceJanuary1,/
publicstaticintgetTotalNumberOfDays(intyear,intmonth){
inttotal=0;
//Getthetotaldaysfromto1/1/year
for(inti=;i<year;i++)万历初年。
if(isLeapYear(i))
total=total+;日历带农历吉日吉时。
else
total=total+;
//AdddaysfromJantothemonthpriortothecalendarmonth
for(inti=1;i<month;i++)
total=total+getNumberOfDaysInMonth(year,i);万年历带农历带吉日的版。
returntotal;/Getthenumberofdaysinamonth/
publicstaticintgetNumberOfDaysInMonth(intyear,intmonth){
if(month==1||month==3||month==5||month==7||
month==8||month==10||month==12)
if(month==4||month==6||month==9||month==11)
if(month==2)returnisLeapYear(year)29:28;
return0;//Ifmonthisincorrect/Determineifitisaleapyear/吉历万年历。
publicstaticbooleanisLeapYear(intyear){万历年是哪一年。
returnyear%==0||(year%4==0&&year%!=0);
以上就是与万年历每天怎么查询相关内容,是关于万年历每天怎么查询的分享。看完万历年日历查询后,希望这对大家有所帮助!
以上就是关于万年历怎么用c#编写全部的内容,包括:万年历怎么用c#编写、C51单片机的万年历程序设计、万年历 编程等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)