万年历代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
int x,y;
for(x = -1;x < Width;x += 3)
for(y = 1;y < Length;y++)
mvprintw(x,y,"-");
for(x = 3;x < Width;x++)
for(y = 1;y < Length;y += 11)
mvprintw(x,y,"|");
int Pre_Year = 0, Pre_Month = 0, Pre_Day =0;//初始化当前日期
int OutputCalendar(int year,int month);//输出万年历
int QueryDate(int *year, int *month);//查询日期
int Leap_Year(int year);//判断闰年 TRUE or FALSE
Pre_Year = 1900 + p -> tm_year;
Pre_Month = 1 + p -> tm_mon;
Pre_Day = p -> tm_mday;
}
//输出万年历
int OutputCalendar(int year, int month)
{
clear();
attron(COLOR_PAIR(4)|A_BOLD);
Month_last = month - 1;
if(Month_last <= 0)
{
Month_last = 12;
Year_last = year - 1;
}
if(Month_last == 2 && Leap_Year(Year_last))//若上年为闰年
Last_Month_Days = 29;
{
if ((year % 4 == 0) && (year % 100 != 0) || year % 400 == 0)
return TRUE;
else
return FALSE;
}
//查询日期
int QueryDate(int *year, int *month)
{
echo();//echo() and noecho(): 此函式用来控制从键盘输入字元时是否将字元显示在终端机上
{
mvprintw( Row,Col,"%d", Days);
Col += 11;
Days++;
}
attron(A_BOLD);
Week_Col = week;
for(Row = 7, Days = 1; Row < 25; Row+=3)//补齐当前月份+下月份
{
for( ; Week_Col < 7; Week_Col++ )
}
else//在当前月补全下个月的日期
{
attron(COLOR_PAIR(3));
attroff(A_BOLD|A_UNDERLINE|A_REVERSE);
init_pair(3,COLOR_CYAN,COLOR_BLACK);
init_pair(4,COLOR_WHITE,COLOR_BLACK);
init_pair(5,COLOR_MAGENTA,COLOR_BLACK);
init_pair(6,COLOR_BLUE,COLOR_BLACK);
init_pair(7,COLOR_YELLOW,COLOR_BLACK);
break;
}
else if(Year_Next == Min_Year)
{
Month_Next = 1;
break;
}
case KEY_RIGHT:
if(Month_Next<Max_Month)
{
Month_Next++;
break;
}
else if(Month_Next >= Max_Month && Year_Next < Max_Year)
break;
}
else
break;
case KEY_LEFT:
if(Month_Next>Min_Month)
{
Month_Next--;
break;
}
else if(Month_Next <= Min_Month && Year_Next > Min_Year)
{
Year_Next -= 1;
Month_Next = 12;
int Week_Day(unsigned int year,unsigned int month,unsigned int day)
{
int week_t = 0;
unsigned int y = 0, c = 0, m = 0, d = 0;
if( month == 1 || month == 2 )
week = Week_Day(year, month, 1);//一号星期几
attron(COLOR_PAIR(1)|A_BOLD|A_UNDERLINE);
mvprintw( 0, 36, " %d-%d ", year, month);
Today = Week_Day(Pre_Year,Pre_Month,Pre_Day);//今天星期几
#define Max_Month 12
#define Min_Month 1
char *Week_Name[7] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
int Sum[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
{//三种日期不同的颜色
if( Days <= Month_Days)
{
if( Days == Pre_Day && month == Pre_Month && year == Pre_Year)//系统当前日颜色
{
attron(COLOR_PAIR(1)|A_BOLD|A_REVERSE);
}
else if(Week_Col == 0 || Week_Col == 6) //周末颜色
//判断是否支持彩色
if(has_colors())
{
start_color();
//初始化颜色配对表
init_pair(0,COLOR_BLACK,COLOR_BLACK);
init_pair(1,COLOR_GREEN,COLOR_BLACK);
init_pair(2,COLOR_RED,COLOR_BLACK);
//计算某一天星期几
int Week_Day(unsigned int year,unsigned int month,unsigned int day);
int GetDate();//得到现在日期
int main()
{
//初始化Cureses包
initscr();
//允许键盘输入字符
keypad(stdscr, TRUE);
else
Last_Month_Days = Sum[Month_last-1];
Days = Last_Month_Days - week + 1; //填充月份第一格的日
attron(COLOR_PAIR(3));
attroff(A_BOLD|A_UNDERLINE);
for(Row = 7,Col = 6,Week_Col = 0; Week_Col < week ; Week_Col++)
{
attron(COLOR_PAIR(2));
attroff(A_REVERSE|A_UNDERLINE);
}
else
{
attron(COLOR_PAIR(4)); //工作日颜色
attroff(A_UNDERLINE|A_REVERSE);
}
mvprintw( Row,Col,"%d", Days);
}
int KEY = 0;
int Year_Next = 0, Month_Next = 0;
GetDate();
Year_Next = Pre_Year;
Month_Next = Pre_Month;
OutputCalendar(Pre_Year, Pre_Month);
curs_set(FALSE); //取消光标
box(stdscr,'|','-');
int Row = 0, Col = 0,Week_Col = 0;//初始化行、列
int Today = 0;//现在星期几
int Days = 0;// 几号
int week = 0;//某天星期几
int Month_Days = 0;
Month_Days = (month == 2 && Leh-1];//当月的天数
curs_set(TRUE);
attron(COLOR_PAIR(7)|A_BOLD);
mvprintw( 1,53,"Please enter date :");
do
{
move(1,72); //光标回到原处
clrtoeol();
scanw("%d%d",year,month);
}while( (*year) > Max_Year || (*year) < Min_Year || (*month) > 12 || (*month) < 1 );
attroff(A_UNDERLINE);
attron(COLOR_PAIR(7));
mvprintw( 1, 5, "Today is %s day", Week_Name[Today]);
attron(COLOR_PAIR(1));
for(Row = 4,Col = 5; Col < Length; Col+=11)
{
mvprintw( Row,Col,"%s", Week_Name[Week_Col] );
Week_Col++;
}
//上个月余下日期及其颜色
int Year_last = 0;
int Month_last = 0;
int Last_Month_Days = 0;
Year_last = year;
week_t = y + y / 4 + c / 4 - 2 * c + 26 * ( m + 1 ) / 10 + d - 1;
week_t = week_t >= 0 ? (week_t % 7) : (week_t % 7 + 7);
return week_t;
}
//判断闰年
int Leap_Year(int year)
noecho();
}
//得到现在日期
int GetDate()
{
time_t timep;
struct tm *p;
time(&timep);
p = localtime(&timep); //此函数获得的tm结构体的时间,是已经进行过时区转化为本地时间
//p = gmtime(&timep); //把日期和时间转换为格林威治(GMT)时间的函数
while(KEY != ESC )
{
KEY = getch();
switch(KEY)
{
case KEY_UP:
if(Year_Next<Max_Year)
{
Year_Next++;
break;
}
else
break;
case KEY_DOWN:
if(Year_Next>Min_Year)
{
Year_Next--;
{
c = (year - 1) / 100;
y = (year - 1) % 100;
m = month + 12;
d = day;
}
else
{
c = year / 100;
y = year % 100;
m = month;
d = day;
}
//蔡勒(Zeller)公式:w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1
#include <stdio.h>
#include <curses.h>
#include <time.h>
#define Length80//长为80
#define Width25//宽为25
#define ESC27
#define Max_Year9999
#define Min_Year1900
break;
case 'F':
QueryDate(&Year_Next, &Month_Next);
curs_set(FALSE);
break;
default:
break;
}
OutputCalendar(Year_Next, Month_Next);
}
endwin();
return 0;
}
//运用蔡勒公式计算某天星期几
{
Year_Next += 1;
Month_Next = 1;
break;
}
else if(Year_Next == Max_Year)
{
Month_Next = 12;
break;
}
case 'f':
QueryDate(&Year_Next, &Month_Next);
curs_set(FALSE);
相关文档
最新文档