本文目录一览:
求C语言编日历源代码的详细说明
/*
稍微改了下对齐格式,加了注释
*/
/*
1、闰年的算法:
如果某年能被4整除但不能被100整除,
或者能被400整除,
则该年是闰年.
用表达式表示就是
(year
%4
==
year%100
!=
0)
||
(year%400
==
0)
2、计算某一天是星期几:
已知1900年的1月1号为星期一,
然后就可以用某一天和1900年的1月1号相差的天数对7取余来求星期,
本题是用的公元1年的1月1号作为基准
*/
#include
stdio.h
#includeconio.h
#includestdlib.h
int
IsLeapYear(int);
//函数定义
void
main()
{
int
i;
int
day;
int
year;
int
temp;
int
temp_i;
long
int
Year_days
=
0;
int
Year_Start
=
1;
int
Per_Year_Days;
int
month_day[]={31,28,31,30,31,30,31,31,30,31,30,31,29};
printf("Please
enter
the
year:
");
scanf("%d",year);
//输入年份
while(Year_Start
year)
//从公元1年开始执行while循环,
该年的一月一号为星期一
{
if(
IsLeapYear(
Year_Start
)
)
Per_Year_Days
=
366;
//如果是闰年,
则一年有366天
else
Per_Year_Days
=
365;
//如果不是闰年,
则一年有365天
Year_days
=
Year_days
+
Per_Year_Days;
//Year_days为从公元1年到输入年份的前一年的天数的总和
Year_Start++;
}
for(
temp
=
1;
temp
=12;
temp++
)
//temp从1到12,
对应一年内12个月
{
switch(
temp
)
//用switch语句将temp和12个月对应起来
{
case
1:
printf("
January(%d)\n",year);
//一月
break;
case
2:
printf("
February(%d)\n",year);
//二月
break;
case
3:
printf("
March(%d)\n",year);
//三月
break;
case
4:
printf("
April(%d)\n",year);
//四月
break;
case
5:
printf("
May(%d)\n",year);
//五月
break;
case
6:
printf("
June(%d)\n",year);
//六月
break;
case
7:
printf("
July(%d)\n",year);
//七月
break;
case
8:
printf("
August(%d)\n",year);
//八月
break;
case
9:
printf("
September(%d)\n",year);
//九月
break;
case
10:
printf("
October(%d)\n",year);
//十月
break;
case
11:
printf("
November(%d)\n",year);
//十一月
break;
case
12:
printf("
December(%d)\n",year);
//十二月
break;
}
i
=
Year_days
%
7;
//每个星期有7天,
故用每年的天数对7取余
printf("Mon\tTue\tWed\tThu\tFri\tSat\tSun\n");
if(
i
!=
)
//如果余数不为零
for(
temp_i
=
0;
temp_i
i;
temp_i++)
printf("\t");
//则打印空格(这里用\t代替空格,
更加美观),
空格数为i
day
=
1;
//初始化day为1,
为下面的while循环做准备
if(
IsLeapYear(year)
temp
==
2)
//如果输入的年份是闰年,
并且月份为2
while(
day
=
month_day[12]
)
//day为一循环变量,
取值为1-365(闰年的话为1-366)
{
if(
day
1
)
//如果天数大于一
if(
Year_days
%
7
==
)
//如果是星期日,
则换行
printf("\n");
if(
day
=
10
)
printf("%d\t",day);
//打印天数+空格
else
printf("%d\t",day);
Year_days++;
day++;
}
else
//如果不满足"输入的年份是闰年,
并且月份为2"
while
(day
=
month_day[temp-1])
{
if(
day
1
)
if(
Year_days
%
7
==
)
printf("\n");
if(
day
=10
)
printf("%d\t",day);
else
printf("%d\t",day);
Year_days++;
day++;
}
printf("\n");
if(
getch()
==
'q'
)
//如果输入为q,
则退出程序
exit(0);
}
getch();
//每按一次键,
打印一个月份
}
int
IsLeapYear(
int
year
)
{
//判断是否是闰年,
是则返回1,
否则返回0
if
((year
%4
==
0)
(year
%
100
!=
0)
||
(year
%
400
==
0)
)
return
1;
else
return
0;
}
苹果节假日日历代码
苹果节假日日历代码如下。
1、在浏览器上输入github.com,(可以在这先选翻译成简体中文)。
2、有账号的话直接登录,没账号的话注册一个账号。
3、注册后登录,然后在上面输入日历订阅。
4、然后会出现个页面,在下面直接复制代码。
5、打开日历,添加日历,添加订阅日历,然后把第4步的代码复制上去就好了。
求日历的HTML代码...
网页台历代码如下:html
head
title网页上的日期台历/title
STYLE
A.menuitem {
COLOR: menutext; TEXT-DECORATION: none
}
A.menuitem:hover {
COLOR: highlighttext; BACKGROUND-COLOR: highlight
}
DIV.contextmenu {
BORDER-RIGHT: 2px outset; BORDER-TOP: 2px outset; Z-INDEX: 999; VISIBILITY: hidden; BORDER-LEFT: 2px outset; BORDER-BOTTOM: 2px outset; POSITION: absolute; BACKGROUND-COLOR: buttonface-日历代码
}
/STYLE
/head
body
SCRIPT language=JavaScript
function Year_Month(){
var now = new Date();
var yy = now.getYear();
var mm = now.getMonth()+1;
var cl = 'font color="#0000df"';
if (now.getDay() == 0) cl = 'font color="#c00000"';
if (now.getDay() == 6) cl = 'font color="#00c000"';
return(cl + yy + '年' + mm + '月/font'); }
function Date_of_Today(){
var now = new Date();
var cl = 'font color="#ff0000"';
if (now.getDay() == 0) cl = 'font color="#c00000"';
if (now.getDay() == 6) cl = 'font color="#00c000"';
return(cl + now.getDate() + '/font'); }
function Day_of_Today(){
var day = new Array();
day[0] = "星期日";
day[1] = "星期一";
day[2] = "星期二";
day[3] = "星期三";
day[4] = "星期四";
day[5] = "星期五";
day[6] = "星期六";
var now = new Date();
///
var cl = 'font color="#0000df"';
if (now.getDay() == 0) cl = 'font color="#c00000"';
if (now.getDay() == 6) cl = 'font color="#00c000"';
return(cl + day[now.getDay()] + '/font'); }
function CurentTime(){
var now = new Date();
var hh = now.getHours();
var mm = now.getMinutes();
var ss = now.getTime() % 60000;
ss = (ss - (ss % 1000)) / 1000;
var clock = hh+':';
if (mm 10) clock += '0';
clock += mm+':';
if (ss 10) clock += '0';
clock += ss;
return(clock); }
function refreshCalendarClock(){
document.all.calendarClock1.innerHTML = Year_Month();
document.all.calendarClock2.innerHTML = Date_of_Today();
document.all.calendarClock3.innerHTML = Day_of_Today();
document.all.calendarClock4.innerHTML = CurentTime(); }
var webUrl = webUrl;
document.write('table border="0" cellpadding="0" cellspacing="0"trtd');
document.write('table id="CalendarClockFreeCode" border="0" cellpadding="0" cellspacing="0" width="60" height="70" ');-日历代码
document.write('style="position:absolute;visibility:hidden" bgcolor="#eeeeee"');
document.write('trtd align="center"font ');
document.write('style="cursor:hand;color:#ff0000;font-size:14pt;line-height:120%" ');
if (webUrl != 'netflower'){
document.write('/td/trtrtd align="center"font ');
document.write('style="cursor:hand;color:#2000ff;font-size:9pt;line-height:110%" ');
}
document.write('/td/tr/table');
document.write('table border="0" cellpadding="0" cellspacing="0" width="61" bgcolor="#C0C0C0" height="70"');-日历代码
document.write('trtd valign="top" width="100%" height="100%"');
document.write('table border="1" cellpadding="0" cellspacing="0" width="58" bgcolor="#FEFEEF" height="67"');-日历代码
document.write('trtd align="center" width="100%" height="100%" ');
document.write('font id="calendarClock1" style="font-size:7pt;line-height:120%"/fontbr');
document.write('font id="calendarClock2" style="color:#ff0000;font-family:Arial;font-size:14pt;line-height:120%"/fontbr');-日历代码
document.write('font id="calendarClock3" style="font-size:9pt;line-height:120%"/fontbr');
document.write('font id="calendarClock4" style="color:#100080;font-size:8pt;line-height:120%"b/b/font');-日历代码
document.write('/td/tr/table');
document.write('/td/tr/table');
document.write('/td/tr/table');
setInterval('refreshCalendarClock()',1000);
/SCRIPT
/body
/html
谁能给一段点击之后出现日历的代码
html
head
title/title
meta http-equiv="Content-Type" content="text/html; charset=gb2312"
/head
body bgcolor="#FFFFFF" text="#000000" leftMargin="0" topMargin="0"
script
Seperator = "-";
var DateStr = "";
// value为指定格式的日期字符串
function SetDateFromCalendar(value)
{
if(top.frames.length0)
{
top.frames("mainFrame").DateObjCtrl_SetDateValue(value);
}
else
{
parent.DateObjCtrl_SetDateValue(value);
}
DateStr = value;
}
// 返回日期字符串
function public_getSelectedDate()
{
return DateStr;
}
/script
script language="JavaScript"
var gdCtrl = new Object();
var gcGray = "#808080";
var gcToggle = "#ffff00";
var gcBG = "#cccccc";
var gdCurDate = new Date();
var giYear = gdCurDate.getFullYear();
var giMonth = gdCurDate.getMonth()+1;
var giDay = gdCurDate.getDate();
var VicPopCal = new Object();
// 显示日历控件
function fPopCalendar(popCtrl, dateCtrl, popCal){
parent.event.cancelBubble=true;
VicPopCal = popCal; // 弹出日历控件的ID
gdCtrl = dateCtrl; // 得到日期数字的控件ID, popCtrl是指定日期控件出现位置的标识
fSetYearMon(giYear, giMonth);
var point = fGetXY(popCtrl); // 得到popCtrl的坐标
with (VicPopCal.style) {
left = point.x;
top = point.y+popCtrl.offsetHeight+1; // 设置日历控件的坐标
visibility = 'visible';
}
VicPopCal.focus();
}
// 隐藏日历控件, 设置gdCtrl的值, 单击今天日期后执行该函数
// 直接得到日期字符串
function fSetDate(iYear, iMonth, iDay){
gdCtrl.value = iMonth+"-"+iDay+"-"+iYear; //Here, you could modify the locale as you need !!!!
VicPopCal.style.visibility = "hidden";
}
// 单击表格执行此函数
function fSetSelected(aCell){
var iOffset = 0;
var iYear = parseInt(tbSelYear.value);
var iMonth = parseInt(tbSelMonth.value);
aCell.bgColor = gcBG;
// 此段代码,控制要是点中的不是当月的日期,自动得到前一个月或后一个月
with (aCell.children["cellText"]){
var iDay = parseInt(innerText);
if (color==gcGray)
iOffset = (Victor10)?-1:1;
iMonth += iOffset;
if (iMonth1) {
iYear--;
iMonth = 12;
}else if (iMonth12){
iYear++;
iMonth = 1;
}
}
// 获得年月日期数
var dateText = parseInt(aCell.innerText);
if(iMonth10)
iMonth = "0" + iMonth;
if(aCell.innerText10)
dateText = "0" + dateText;
// 将年月日组成指定字符串传给回传函数
SetDateFromCalendar(iYear + Seperator + iMonth + Seperator + dateText);
}
// 指定当前object的显示位置
function Point(iX, iY){
this.x = iX;
this.y = iY;
}
// 建立当月的日期数组
function fBuildCal(iYear, iMonth) { // 传过来的月加了1,表示下一月
var aMonth=new Array();
for(i=1;i7;i++)
aMonth[i]=new Array(i);
// 创建当前月第一天日期对象
var dCalDate=new Date(iYear, iMonth-1, 1);
var iDayOfFirst=dCalDate.getDay();//得到该日是星期几
var iDaysInMonth=new Date(iYear, iMonth, 0).getDate();// 得到下一月
var iOffsetLast=new Date(iYear, iMonth-1, 0).getDate()-iDayOfFirst+1;
var iDate = 1;
var iNext = 1;
for (d = 0; d 7; d++)
aMonth[1][d] = (diDayOfFirst)?-(iOffsetLast+d):iDate++;
for (w = 2; w 7; w++)
for (d = 0; d 7; d++)
aMonth[w][d] = (iDate=iDaysInMonth)?iDate++:-(iNext++);
return aMonth;
}
// 画出星期title,和显示数据
function fDrawCal(iYear, iMonth, iCellWidth, iDateTextSize) {
var WeekDay = new Array("日","一","二","三","四","五","六");
var styleTD = " bgcolor='"+gcBG+"' width='"+iCellWidth+"' bordercolor='"+gcBG+"' valign='middle' align='center' style='font:bold "+iDateTextSize+" Courier;"; -日历代码
with (document) {
write("tr");
for(i=0; i7; i++)
write("td "+styleTD+"color:#990099' " + WeekDay[i] + "/td");
write("/tr");
for (w = 1; w 7; w++) {
write("tr");
for (d = 0; d 7; d++) {
write("td id=calCell "+styleTD+"cursor:hand;' onMouseOver='this.bgColor=gcToggle' onMouseOut='this.bgColor=gcBG' onclick='fSetSelected(this)'");-日历代码
write("font id=cellText Victor='KinLee' /font");
write("/td")
}
write("/tr");
}
}
}
// 填入表格日期数据,可用的和不可用的用不同的底色来区分
function fUpdateCal(iYear, iMonth) {
myMonth = fBuildCal(iYear, iMonth); // 初始化当月的日期显示数组
var i = 0;
for (w = 0; w 6; w++)
for (d = 0; d 7; d++)
with (cellText[(7*w)+d]) { // cellText是表格的标识,都叫cellText,用下标来指示
Victor = i++;
if (myMonth[w+1][d]0) {
color = gcGray;
innerText = -myMonth[w+1][d];
}else{
color = ((d==0)||(d==6))?"red":"black"; // 星期六、日颜色为红色
innerText = myMonth[w+1][d];
}
}
}
// 在下拉框中选中当前年和月, 然后更新数据显示
function fSetYearMon(iYear, iMon){
tbSelMonth.options[iMon-1].selected = true;
for (i = 0; i tbSelYear.length; i++)
if (tbSelYear.options[i].value == iYear)
tbSelYear.options[i].selected = true;
fUpdateCal(iYear, iMon);
}
// 上一月
function fPrevMonth(){
var iMon = tbSelMonth.value;
var iYear = tbSelYear.value;
if (--iMon1) {
iMon = 12;
iYear--;
}
fSetYearMon(iYear, iMon);
}
// 下一月
function fNextMonth(){
var iMon = tbSelMonth.value;
var iYear = tbSelYear.value;
if (++iMon12) {
iMon = 1;
iYear++;
}
fSetYearMon(iYear, iMon);
}
function fGetXY(aTag){
var oTmp = aTag;
var pt = new Point(0,0);
do {
pt.x += oTmp.offsetLeft;
pt.y += oTmp.offsetTop;
oTmp = oTmp.offsetParent;
} while(oTmp.tagName!="BODY");
return pt;
}
var gMonths = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
//打印出年月日的显示的表格,之后再填入数字
with (document) {
write("table id='popTable' border='0' bgcolor='#6699cc'");
write("TR");
write("td valign='middle' align='center'input type='button' name='PrevMonth' value='' style='height:20;width:20;FONT:16 Fixedsys' onClick='fPrevMonth()'");-日历代码
write(" SELECT name='tbSelYear' onChange='fUpdateCal(tbSelYear.value, tbSelMonth.value)' Victor='Won'");-日历代码
for(i=2000;i3000;i++)
write("OPTION value='"+i+"'"+i+"/OPTION");
write("/SELECT");
write(" select name='tbSelMonth' onChange='fUpdateCal(tbSelYear.value, tbSelMonth.value)' Victor='Won'");-日历代码
for (i=0; i12; i++)
write("option value='"+(i+1)+"'"+gMonths[i]+"/option");
write("/SELECT");
write(" input type='button' name='NextMonth' value='' style='height:20;width:20;FONT:16 Fixedsys' onclick='fNextMonth()'");-日历代码
write("/td");
write("/TRTR");
write("td align='center'");
write("DIV style='background-color:teal;'table width='100%' border='0' cellpadding='2'");
fDrawCal(giYear, giMonth, 19, 12);
write("/table/DIV");
write("/td");
write("/TRTRTD align='center'");
write("font style='cursor:hand;font:12 Fixedsys' onclick='fSetDate(giYear,giMonth,giDay)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=0'今天是: "+giYear+"年"+gMonths[giMonth-1]+"月"+giDay+"日"+"/font");-日历代码
write("/TD/TR");write("/TD/TR");
write("/TABLE");
}
var today = new Date();
// 用当前的日期更新月历显示
fSetYearMon(today.getFullYear(), today.getMonth() + 1);
// 填入表格日期数据,可用的和不可用的用不同的底色来区分
//fUpdateCal(today.getFullYear(), today.getMonth() + 1);
/script
/body
/html