安卓日历开发源代码
JAVA课程设计 万年历 源代码
![JAVA课程设计 万年历 源代码](https://img.taocdn.com/s3/m/0f7dbef4f021dd36a32d7375a417866fb84ac0f4.png)
测试用例设计:根据 需求文档和功能描述, 设计出能够覆盖所有 功能的测试用例
测试工具:使用JUnit 等测试框架进行单元 测试,使用Selenium 等工具进行UI测试
测试结果分析:根 据测试结果,分析 代码存在的问题, 并进行修改和优化
集成测试:验证各个模块之间的接口是否正确,数据传输是否正常 性能测试:测试系统的响应时间、吞吐量、资源利用率等性能指标
提醒功能:用户可以设置提醒功能,在节日或假期到来之前,系统会自动提醒用户。
删除事件:用户可以删除不 再需要的事件
编辑事件:用户可以对已添加 的事件进行编辑,如修改事件 名称、时间等
添加事件:用户可以在万年历 中添加新的事件,如生日、纪 念日等
查询事件:用户可以查询特定 日期或时间段内的事件,如查
界面显示:万年历界面将显示年、 月、日、星期等信息,用户可以通 过点击相应的按钮来切换日期。
添加标题
添加标题
添加标题
添加标题
系统响应:当用户输入日期后,系统 将根据输入的日期显示相应的万年历 信息,包括年、月、日、星期等信息。
用户操作:用户可以通过点击相应 的按钮来切换日期,系统将根据用 户的操作显示相应的万年历信息。
添加标题
界面设计:简洁明了,易于阅读
添加标题
添加标题
交互性:用户可以选择查看不同日 期的日历信息
功能描述:在万年历中,用户可以选择标注节日和假期,以便于查看和提醒。
节日标注:用户可以在万年历中设置自己喜欢的节日,如春节、中秋节等,系统会自动 标注这些节日。
假期标注:用户可以在万年历中设置自己的假期,如年假、病假等,系统会自动标注这 些假期。
,a click to unlimited possibilities
android2.1 自定义日历控件
![android2.1 自定义日历控件](https://img.taocdn.com/s3/m/1963a529ed630b1c59eeb588.png)
package com.threeeyes.util;import java.util.Calendar;import com.threeeyes.activity.R;import android.R.color;import android.app.Activity;import android.content.Context;import android.graphics.Color;import android.os.Bundle;import android.util.Log;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ImageButton;import android.widget.LinearLayout;import android.widget.TableLayout;import android.widget.TableRow;import android.widget.TextView;import android.widget.Toast;import youtParams;public class DateTime extends LinearLayout {TableLayout table;TextView showDateTxt;TextView btnpre;TextView btnnext;TextView nowDate;int year;int month; // 0,1,..,,11int srcday; // 初始日int srcyear; // 初始年int srcmonth; // 初始月String[] weeks = { "周日", "周一", "周二", "周三", "周四", "周五", "周六" };View preSelectedView = null; // 前一个选中的日期Context ct;DateCallBack callBack;int weekTitleColor = 0xFFFF0000;int dayColor = 0xFFFF0000;int titleColor = Color.BLACK;int selectedColor = Color.TRANSPARENT;boolean init = false; // 初始化标志int colWidth = 30; // 单元格宽度int rowHeight = 0; // 单元格高度int textSize = 12;LinearLayout dayLayOut;public DateTime(Context context, final int year1, final int month1, int day1) { super(context);ct = context;this.srcmonth=month1;this.srcyear=year1;setOrientation(LinearLayout.VERTICAL);setLayoutParams(new LayoutParams(youtParams.WRAP_CONTENT,youtParams.WRAP_CONTENT));setBackgroundColor(Color.GRAY);LinearLayout titleLayOut = new LinearLayout(ct);titleLayOut.setOrientation(LinearLayout.HORIZONTAL);titleLayOut.setGravity(Gravity.CENTER_HORIZONTAL);addView(titleLayOut);table = new TableLayout(ct);addView(table);showDateTxt = new TextView(ct);youtParams la = new youtParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);la.rightMargin = 20;la.leftMargin = 20;showDateTxt.setLayoutParams(la);showDateTxt.setTextSize(textSize);this.year = year1;if (month1 < 1 || month1 > 12)this.month = 0;elsethis.month = month1 - 1;if (day1 < 1 || day1 > 31)this.srcday = 1;elsethis.srcday = day1;showDateTxt.setText(String.valueOf(year1) + "年" + String.valueOf(month1)); showDateTxt.setTextColor(titleColor);btnpre = new TextView(ct);btnpre.setTextColor(titleColor);btnpre.setText("上月");btnpre.setTextSize(textSize);btnnext = new TextView(ct);btnnext.setTextColor(titleColor);btnnext.setText("下月");btnnext.setTextSize(textSize);nowDate = new TextView(ct);nowDate.setTextColor(titleColor);nowDate.setText("今天");nowDate.setTextSize(textSize);nowDate.setGravity(Gravity.CENTER_HORIZONTAL);dayLayOut = new LinearLayout(ct);dayLayOut.setOrientation(LinearLayout.VERTICAL);dayLayOut.setGravity(Gravity.CENTER_VERTICAL);dayLayOut.addView(showDateTxt);dayLayOut.addView(nowDate);titleLayOut.addView(btnpre);titleLayOut.addView(dayLayOut);titleLayOut.addView(btnnext);nowDate.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubyear = srcyear;month = srcmonth-1;showDateTxt.setText(String.valueOf(year) + "年"+ String.valueOf(month + 1) + "月");loadDate(1,1+5);}});btnnext.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubif (preSelectedView != null)preSelectedView.setBackgroundColor(color.transparent);nextMonth();showDateTxt.setText(String.valueOf(year) + "年"+ String.valueOf(month + 1) + "月");loadDate(1, 1 + 5);}});btnpre.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubpreMonth();showDateTxt.setText(String.valueOf(year) + "年"+ String.valueOf(month + 1) + "月");loadDate(1, 1 + 5);}});}public void setPre_Next_BackGround(int preRes, int nextPre) {btnpre.setBackgroundResource(preRes);btnnext.setBackgroundResource(nextPre);btnpre.setText("");btnnext.setText("");}public void setNowDateBackGround(int res) {dayLayOut.setBackgroundResource(res);}/*** 初始化日期** @param titleCoclor* 标题颜色* @param weekTitleColor* 星期颜色* @param dayColor* 日期颜色*/public void initDate(int titleCoclor, int weekTitleColor, int dayColor, int selectedColor) {if (!init) {this.weekTitleColor = weekTitleColor;this.dayColor = dayColor;this.titleColor = titleCoclor;showDateTxt.setTextColor(titleCoclor);btnpre.setTextColor(titleCoclor);btnnext.setTextColor(titleCoclor);this.selectedColor = selectedColor;generateDate();}}/*** 初始化日期颜色默认*/public void initDate() {if (!init) {generateDate();}}/*** 以"周日","周一","周二","周三","周四","周五","周六"为顺序** @param weekdays*/public void setWeekTitle(String[] weekdays) {if (weekdays != null && weekdays.length > 0 && weekdays.length == 7) this.weeks = weekdays;}public int maxDay() {Calendar time = Calendar.getInstance();Log.v("", time.toString());time.clear();time.set(Calendar.YEAR, year);time.set(Calendar.MONTH, month);int day = time.getActualMaximum(Calendar.DAY_OF_MONTH);// 本月份的天数return day;}public int nowWeekDay() {Calendar time = Calendar.getInstance();Log.v("", time.toString());time.clear();time.set(Calendar.YEAR, year);time.set(Calendar.MONTH, month);time.set(Calendar.DATE, 1);int weekday = time.get(Calendar.DAY_OF_WEEK);if (weekday == 7)return 0;elsereturn weekday - 1;}public void generateDate() {youtParams params = new youtParams(youtParams.WRAP_CONTENT,youtParams.WRAP_CONTENT);TableRow row2 = new TableRow(ct);row2.setPadding(0, 2, 0, 0);row2.setGravity(Gravity.CENTER_HORIZONTAL);for (int i = 0; i < 7; i++) {TextView col1 = new TextView(ct);col1.setMinWidth(colWidth);col1.setMaxWidth(colWidth);if (rowHeight > 0)col1.setMinHeight(rowHeight);col1.setTextColor(weekTitleColor);col1.setText(weeks[i]);col1.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);col1.setTextSize(textSize);row2.addView(col1); // 添加列}table.addView(row2);int weekday = nowWeekDay();int maxday = maxDay();Log.v("date----", weekday + "-----------" + maxday);int count = 0;for (int i = 0; i < 5; i++) { // 添加6行TableRow row = new TableRow(ct);row.setPadding(0, 2, 0, 2);row.setGravity(Gravity.CENTER_HORIZONTAL);row.setLayoutParams(params);// row.setBackgroundColor(0xFF00FF00);for (int j = 0; j < 7; j++) { // 添加1列TextView col = new TextView(ct);col.setTextColor(dayColor);col.setBackgroundColor(color.transparent);col.setTextSize(textSize);if (rowHeight > 0)col.setMinHeight(rowHeight);if (i == 0) {if (weekday <= j) {count++;col.setText(String.valueOf(count));}} else {if (count < maxday) {count++;col.setText(String.valueOf(count));}}col.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubif (((TextView) v).getText().toString().length() > 0) {if (preSelectedView != null) {preSelectedView.setBackgroundColor(color.transparent);}preSelectedView = v;v.setBackgroundColor(selectedColor);callBack.execute(v, year + "", (month + 1) + "",((TextView) v).getText().toString());}}});if (srcday == count) {col.setBackgroundColor(selectedColor);this.preSelectedView = col;}col.setGravity(Gravity.CENTER_HORIZONTAL| Gravity.CENTER_VERTICAL);row.addView(col); // 添加列}table.addView(row);// 添加行}}public void nextMonth() {if (month == 11) {year++;month = 0;} else {month++;}}public void preMonth() {if (month == 0) {year--;month = 11;} else {month--;}}public void loadDate(int startIndex, int endIndex) {int weekday = nowWeekDay();int maxday = maxDay();Log.v("date----", weekday + "-----------" + maxday);int count = 0;for (int i = startIndex; i < endIndex; i++) {TableRow row = (TableRow) table.getChildAt(i);for (int j = 0; j < 7; j++) {TextView col = (TextView) row.getChildAt(j);if (i == startIndex) {if (weekday <= j) {count++;col.setText(String.valueOf(count));if (srcday == count) {col.setBackgroundColor(selectedColor);this.preSelectedView = col;}} else {col.setText("");}} else {if (count < maxday) {count++;col.setText(String.valueOf(count));} else {col.setText("");}}if (srcday == count) {col.setBackgroundColor(selectedColor);if (this.preSelectedView != col)this.preSelectedView.setBackgroundColor(color.transparent);this.preSelectedView = col;}}}}/*** 回调函数** @author Acer**/public interface DateCallBack {public void execute(View v, String year, String month, String day);}public void setCallBack(DateCallBack callBack) {this.callBack = callBack;}/*** 设置单元格的宽度,高度** @param colWidth* 单元格宽度* @param rowHeight* 单元格高度* @param textSize1* 文字大小*/public void setWidthHeightTextSize(int colWidth, int rowHeight,int textSize1) {if (colWidth > 0)this.colWidth = colWidth;this.rowHeight = rowHeight;this.textSize = textSize1;btnpre.setTextSize(textSize1);btnnext.setTextSize(textSize1);showDateTxt.setTextSize(textSize1);}}。
精美日历的程序设计及代码示例
![精美日历的程序设计及代码示例](https://img.taocdn.com/s3/m/853af887d4bbfd0a79563c1ec5da50e2534dd111.png)
精美日历的程序设计及代码示例一、引言日历是我们日常生活中重要的时间管理工具。
一个精美美观的日历设计可以提升用户的使用体验。
本文将介绍精美日历的程序设计方法以及相应的代码示例。
二、设计思路1. 日历显示界面设计精美日历应该具备以下设计要素:- 界面简洁明了,突出重要信息;- 适配不同设备屏幕尺寸,保证用户在不同设备上都能良好显示;- 使用合适的字体、颜色和布局,营造舒适的阅读体验;- 支持用户自定义主题,以满足不同用户的个性化需求。
2. 日历功能设计精美日历的功能设计要考虑以下几点:- 显示当前日期以及所在月份,方便用户快速查看;- 支持切换月份,以便查看过去或未来的日期;- 标记重要日期,例如节假日、生日等,以便用户一目了然;- 提供日程管理功能,允许用户添加、编辑和删除日程安排;- 支持农历显示,满足中国用户的需求。
三、代码示例下面是一个简单的精美日历的代码示例,代码使用HTML、CSS和JavaScript编写。
```<!DOCTYPE html><html><head><title>精美日历</title><style>/* CSS样式 *//* 省略部分样式代码,包括字体、颜色和布局等 */</style></head><body><div id="calendar"><div id="header"><button id="prevBtn">上个月</button><div id="title"></div><button id="nextBtn">下个月</button> </div><table id="days"><tr><th>周一</th><th>周二</th><th>周三</th><th>周四</th><th>周五</th><th>周六</th><th>周日</th></tr><!-- 日期格子动态生成 --></table></div><script>// JavaScript代码// 获取当前日期var date = new Date();var currentYear = date.getFullYear();var currentMonth = date.getMonth() + 1;// 标记重要日期var importantDates = [5, 10, 15];// 更新日历显示function updateCalendar(year, month) {// 更新标题document.getElementById("title").innerHTML = year + "年" + month + "月";// 清空日期格子var table = document.getElementById("days");table.getElementsByTagName("tbody")[0].innerHTML = "";// 获取本月第一天的日期对象var firstDay = new Date(year, month - 1, 1);var startDay = firstDay.getDay(); // 本月第一天是星期几// 动态生成日期格子var dateIndex = 1;var tr = document.createElement("tr");for (var i = 0; i < startDay; i++) {tr.innerHTML += "<td></td>";}while (firstDay.getMonth() === month - 1) {if (startDay === 0) {table.getElementsByTagName("tbody")[0].appendChild(tr); tr = document.createElement("tr");}var td = document.createElement("td");td.innerHTML = dateIndex;if (importantDates.includes(dateIndex)) {td.classList.add("important"); // 添加重要日期样式}tr.appendChild(td);dateIndex++;firstDay.setDate(firstDay.getDate() + 1);startDay = firstDay.getDay();}table.getElementsByTagName("tbody")[0].appendChild(tr);}// 切换月份document.getElementById("prevBtn").addEventListener("click", function() {if (currentMonth === 1) {currentYear--;currentMonth = 12;} else {currentMonth--;}updateCalendar(currentYear, currentMonth);});document.getElementById("nextBtn").addEventListener("click", function() {if (currentMonth === 12) {currentYear++;currentMonth = 1;} else {currentMonth++;}updateCalendar(currentYear, currentMonth);});// 初始化日历updateCalendar(currentYear, currentMonth);</script></body></html>```四、总结本文介绍了精美日历的程序设计方法及相应的代码示例。
c日历源代码
![c日历源代码](https://img.taocdn.com/s3/m/acfd1ee66294dd88d0d26b39.png)
#include <stdio.h>#include <windows.h>void month(int a)//输出月份和星期{printf("\t");switch (a){case 1:printf("Janurary 1\t\t\t\t");case 2:printf("February 2");break;case 3:printf("March 3 \t\t\t\t");case 4:printf("April 4");break;case 5:printf("May 5 \t\t\t\t");case 6:printf("June 6");break;case 7:printf("July 7 \t\t\t\t");case 8:printf("August 8");break;case 9:printf("September 9 \t\t\t");case 10:printf("October 10");break;case 11:printf("November 11 \t\t\t");case 12:printf("December 12");break;}printf("\n\t");printf("Sun Mon Tue Wed Thu Fri Sat\t\t");printf("Sun Mon Tue Wed Thu Fri Sat\n\t");}int date(int a,int b,int c)//输出日期a为月份b为判断润平年r为某月最后一天的星期数{void space(int a);int i,j,n,m,x=1,y,k=0;switch (a){case 1:n=31;break;case 3:n=31;m=30;break;case 5:n=31;m=30;break;case 7:n=31;m=31;break;case 9:n=30;m=31;break;case 11:n=30;m=31;break;}if (a==1)if (b==0)m=28;elsem=29;for (i=1,j=c;i<=n;i++,j++){printf("%2d ",i);if (j==7 && i!=n){j=0;printf("\t\t");for (y=1;x<=m;y++){if (k==0){c=(c+n-1)%7+1;while (c>7)c=c-7;space(c);y=c;k=1;if (y<1)y=1;}printf("%2d ",x);if (y==7 && x!=m){x++;printf("\n\t");y=0;break;}if (x==m && y==7){x++;printf("\n\t");y=0;break;}if (x==m && y!=7)printf("\n\t");x++;}}if (i==n && j==7){j=0;i=0;break;}}if (i!=0)while (7-j){printf(" ");j=1+j;}printf("\t\t");if (x<=m)for (y=1;x<=m;y++,x++){printf("%2d ",x);if (y==7 && x!=m){printf("\n\t\t\t\t\t\t");y=0;}}printf("\n\t===========================\t\t");printf("===========================\n\n");if (y>7 || y==0)y=1;return y;}int leap(int a)//判断是否为闰年{int n;if ((a%4==0 && a%100!=0) || a%400==0)n=1;elsen=0;return n;}int print()//输出日历{void shxi(int a);void ganzhi(int a);void space(int a);int n,days,year,result,r,i,week,rem;while (1){printf("\t\t请输入年份:");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),12|240);//设置字体颜色i=scanf("%d",&year);if (i==1){SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0|240);break;}elsefflush(stdin);printf("\t\t错误输入!\n");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0|240);}ganzhi(year);shxi(year);n=leap(year);if (n)days=366;elsedays=365;result=(year-1+(year-1)/4-(year-1)/100+(year-1)/400+days)%7-n;//一月一号星期几的判断公式r=result+1;week=(days+result)/7;rem=(days +result)%7;if (rem!=0) week=week+rem/7+1;//计算这一年有多少周printf("\t\t\t\t\t%d周\n",week);printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");for (i=1;i<=12;i+=2){month(i);space(r);r=date(i,n,r);}printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");return 0;}void space(int a)//输出空格{int i;for (i=0;i<a-1;i++)printf(" ");}int main()//主程序输出选择菜单{void fprint();int n;system("color f0");//设置背景和字体颜色do{printf("\t\t* * * * * * * * * * * * * * * * * * * * * *\n");printf("\t\t*\t1---查询(Search) *\n");printf("\t\t*\t2---导出(Lead) *\n");printf("\t\t*\t0---关闭(Close) *\n");printf("\t\t* * * * * * * * * * * * * * * * * * * * * *\n");printf("\t\t请选择:");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),12|240);//设置字体颜色scanf("%d",&n);system("cls");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0|240);switch (n){case 1:print();break;case 2:fprint();break;case 0:break;default:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),12|240);printf("\ t\t错误选择!请重选");}fflush(stdin);printf("\n");} while(n!=0);return 0;}void shxi(int a)//判断这一年的属性并输出{int s;if (a>=2008) //属性判断公式s=((a-2008)%100)%12+1;elses=13-((2008-a)%100)%12;switch (s){case 1:printf("鼠");break;case 2:printf("牛");break;case 3:printf("虎");break;case 4:printf("兔");break;case 5:printf("龙");break;case 6:printf("蛇");break;case 7:printf("马");break;case 8:printf("羊");break;case 9:printf("猴");break;case 10:printf("鸡");break;case 11:printf("狗");break;case 12:printf("猪");break;}}void ganzhi(int a)//判断天干地支{int g,z;g=(a-3)%10;//天干判断公式z=(a-3)%12;//地支判断公式printf("\t\t\t");switch (g){case 1:printf("甲");break;case 2:printf("乙");break;case 3:printf("丙");break;case 4:printf("丁");break;case 5:printf("戊");break;case 6:printf("己");break;case 7:printf("庚");break;case 8:printf("辛");break;case 9:printf("壬");break;case 0:printf("癸");break;}switch (z){case 1:printf("子");break;case 2:printf("丑");break;case 3:printf("寅");break;case 4:printf("卯");break;case 5:printf("辰");break;case 6:printf("巳");break;case 8:printf("未");break;case 9:printf("申");break;case 10:printf("酉");break;case 11:printf("戌");break;case 0:printf("亥");break;}printf("年\t");}FILE *fp;//定义文件指针void fmonth(int a)//导出月份和星期{fprintf(fp,"\t");switch (a){case 1:fprintf(fp,"Janurary 1\t\t\t\t");case 2:fprintf(fp,"February 2");break;case 3:fprintf(fp,"March 3 \t\t\t\t");case 4:fprintf(fp,"April 4");break;case 5:fprintf(fp,"May 5 \t\t\t\t");case 6:fprintf(fp,"June 6");break;case 7:fprintf(fp,"July 7 \t\t\t\t");case 8:fprintf(fp,"August 8");break;case 9:fprintf(fp,"September 9 \t\t\t");case 10:fprintf(fp,"October 10");break;case 11:fprintf(fp,"November 11 \t\t\t");case 12:fprintf(fp,"December 12");break;}fprintf(fp,"\n\t");fprintf(fp,"Sun Mon Tue Wed Thu Fri Sat\t\t");fprintf(fp,"Sun Mon Tue Wed Thu Fri Sat\n\t"); }int fdate(int a,int b,int c)//导出日期{int i,j,n,m,x=1,y,k=0,r;switch (a){case 1:n=31;break;case 3:n=31;m=30;break;case 5:n=31;m=30;break;case 7:n=31;m=31;break;case 11:n=30;m=31;break;}if (a==1)if (b==0)m=28;elsem=29;for (i=1,j=c;i<=n;i++,j++){fprintf(fp,"%2d ",i);if (j==7 && i!=n){j=0;fprintf(fp,"\t\t");for (y=1;x<=m;y++){if (k==0){c=(c+n-1)%7+1;while (c>7)c=c-7;for (r=0;r<c-1;r++)fprintf(fp," ");y=c;k=1;if (y<1)y=1;}fprintf(fp,"%2d ",x);if (y==7 && x!=m){x++;fprintf(fp,"\n\t");y=0;break;}if (x==m && y==7){x++;fprintf(fp,"\n\t");y=0;break;}if (x==m && y!=7)fprintf(fp,"\n\t");x++;}}if (i==n && j==7){j=0;i=0;break;}}if (i!=0)while (7-j){fprintf(fp," ");j=1+j;}fprintf(fp,"\t\t");if (x<=m)for (y=1;x<=m;y++,x++){fprintf(fp,"%2d ",x);if (y==7 && x!=m){fprintf(fp,"\n\t\t\t\t\t\t");y=0;}}fprintf(fp,"\n\t===========================\t\t");fprintf(fp,"===========================\n\n");if (y>7 || y==0)y=1;return y;}void fprint()//导出文件{void fshxi(int a);void fganzhi(int a);void fspace(int a);int n,days,year,result,r,i,week,rem;char filename[10],type[]=".txt";while (1){printf("\t\t请输入年份:");i=scanf("%d",&year);if (i==1)break;elsefflush(stdin);printf("\t\t错误输入!\n");}printf("\t\t请输入导出文件名:");scanf("%s",&filename);fp=fopen(strcat(filename,type),"w");//以写的方式打开文件fganzhi(year);fshxi(year);n=leap(year);if (n)days=366;elsedays=365;result=(year-1+(year-1)/4-(year-1)/100+(year-1)/400+days)%7-n;r=result+1;week=(days+result)/7;rem=(days +result)%7;if (rem!=0) week=week+rem/7+1;fprintf(fp,"\t\t\t\t\t\t\t\t%d周\n",week);fprintf(fp," * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");for (i=1;i<=12;i+=2){fmonth(i);fspace(r);r=fdate(i,n,r);}fprintf(fp," * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");fclose(fp);//关闭文件printf("\t\t已导出完成");}void fspace(int a)//导出空格{int i;for (i=0;i<a-1;i++)fprintf(fp," ");}void fshxi(int a)//导出属性{int s;if (a>=2008)s=((a-2008)%100)%12+1;elses=13-((2008-a)%100)%12;switch (s){case 1:fprintf(fp,"鼠");break;case 2:fprintf(fp,"牛");break;case 3:fprintf(fp,"虎");break;case 4:fprintf(fp,"兔");break;case 5:fprintf(fp,"龙");break;case 6:fprintf(fp,"蛇");break;case 7:fprintf(fp,"马");break;case 8:fprintf(fp,"羊");break;case 9:fprintf(fp,"猴");break;case 10:fprintf(fp,"鸡");break;case 11:fprintf(fp,"狗");break;case 12:fprintf(fp,"猪");break;}fprintf(fp,"\n");}void fganzhi(int a)//导出天干地支{int g,z;g=(a-3)%10;z=(a-3)%12;fprintf(fp,"\t\t\t%d年\t\t",a);switch (g){case 1:fprintf(fp,"甲");break;case 2:fprintf(fp,"乙");break;case 3:fprintf(fp,"丙");break;case 4:fprintf(fp,"丁");break;case 5:fprintf(fp,"戊");break;case 6:fprintf(fp,"己");break;case 7:fprintf(fp,"庚");break;case 8:fprintf(fp,"辛");break;case 9:fprintf(fp,"壬");break;case 0:fprintf(fp,"癸");break;}switch (z){case 1:fprintf(fp,"子");break;case 2:fprintf(fp,"丑");break;case 3:fprintf(fp,"寅");break;case 4:fprintf(fp,"卯");break;case 5:fprintf(fp,"辰");break;case 6:fprintf(fp,"巳");break;case 7:fprintf(fp,"午");break;case 8:fprintf(fp,"未");break;case 9:fprintf(fp,"申");break;case 10:fprintf(fp,"酉");break;case 11:fprintf(fp,"戌");break;case 0:fprintf(fp,"亥");break;}fprintf(fp,"年\t");}。
JAVA----日历源代码
![JAVA----日历源代码](https://img.taocdn.com/s3/m/f675b611bfd5b9f3f90f76c66137ee06eff94ed1.png)
JAVA----⽇历源代码1:先创建⼀个CalendarBean类:代码:1. import java.util.Calendar;2. public class CalendarBean3. {4. String day[];5. int year=2005,month=0;6. public void setYear(int year)7. {8. this.year=year;9. }10. public int getYear()11. {12. return year;13. }14. public void setMonth(int month)15. {16. this.month=month;17. }18. public int getMonth()19. {20. return month;21. }22. public String[] getCalendar()23. {24. String a[]=new String[42];25. Calendar date=Calendar.getInstance();26. date.set(year,month-1,1);27. int week=date.get(Calendar.DAY_OF_WEEK)-1;28. int day=0;29. //判断⼤⽉份30. if(month==1||month==3||month==5||month==731. ||month==8||month==10||month==12)32. {33. day=31;34. }35. //判断⼩⽉36. if(month==4||month==6||month==9||month==11)37. {38. day=30;39. }40. //判断平年与闰年41. if(month==2)42. {43. if(((year%4==0)&&(year%100!=0))||(year%400==0))44. {45. day=29;46. }47. else48. {49. day=28;50. }51. }52. for(int i=week,n=1;i<week+day;i++)53. {54. a[i]=String.valueOf(n) ;55. n++;56. }57. return a;58. }59. }2:创建⼀个CalendarFrame类import javax.swing.*;public class CalendarFrame extends JFrame implements ActionListener {JLabel labelDay[]=new JLabel[42];JTextField text=new JTextField(10);JButton titleName[]=new JButton[7];JButton button=new JButton();String name[]={"⽇","⼀","⼆","三","四","五","六"};JButton nextMonth,previousMonth;int year=1996,month=1;CalendarBean calendar;JLabel showmessage=new JLabel("",JLabel.CENTER);JLabel lbl1=new JLabel("请输⼊年份:");JLabel lbl2=new JLabel(" ");public CalendarFrame(){JPanel pCenter=new JPanel();//将pCenter的布局设置为7⾏7列的GridLayout布局pCenter.setLayout(new GridLayout(7,7));//pCenter添加组件titleName[i]for(int i=0;i<7;i++){titleName[i]=new JButton(name[i]);pCenter.add(titleName[i]);}//pCenter添加组件LabelDay[i]for(int i=0;i<42;i++){labelDay[i]=new JLabel("",JLabel.CENTER);pCenter.add(labelDay[i]);}text.addActionListener(this);calendar=new CalendarBean();calendar.setYear(year);calendar.setMonth(month);String day[]=calendar.getCalendar();for(int i=0;i<42;i++){labelDay[i].setText(day[i]);}nextMonth=new JButton("下⽉");previousMonth=new JButton("上⽉");button=new JButton("确定");//注册监听器nextMonth.addActionListener(this);previousMonth.addActionListener(this);button.addActionListener(this);JPanel pNorth=new JPanel(),pSouth=new JPanel();pNorth.add(showmessage);pNorth.add(lbl2);pNorth.add(previousMonth);pNorth.add(nextMonth);pSouth.add(lbl1);pSouth.add(text);pSouth.add(button);showmessage.setText("⽇历"+calendar.getYear()+"年"+calendar.getMonth()+"⽉"); ScrollPane scrollPane=new ScrollPane();scrollPane.add(pCenter);add(scrollPane,BorderLayout.CENTER);//窗⼝添加到ScrollPane 中间位置add(pNorth,BorderLayout.NORTH); //窗⼝添加pNorth在窗⼝北⾯add(pSouth,BorderLayout.SOUTH); //窗⼝添加pSouth在窗⼝的南⾯}public void actionPerformed(ActionEvent e){if(e.getSource()==nextMonth){month+=1;if(month>12)month=1;calendar.setMonth(month);String day[]=calendar.getCalendar();for(int i=0;i<42;i++){labelDay[i].setText(day[i]);}}else if(e.getSource()==button){month+=1;if(month>12)month=1;calendar.setYear(Integer.parseInt(text.getText()));String day[]=calendar.getCalendar();for(int i=0;i<42;i++){labelDay[i].setText(day[i]);}showmessage.setText("⽇历"+calendar.getYear()+"年"+calendar.getMonth()+"⽉"); }}}3:在创建⼀个CalendarMainClass类代码:import javax.swing.JFrame;import javax.swing.UIManager;public class CalendarMainClass {public static void main(String[]args){try{UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); }catch(Exception e){e.printStackTrace();}CalendarFrame frame=new CalendarFrame();frame.setBounds(100,100,360,300);frame.setTitle("中华⽇历");frame.setLocationRelativeTo(null);//窗体居中显⽰frame.setVisible(true);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}}运⾏结果:。
android日历毕业设计
![android日历毕业设计](https://img.taocdn.com/s3/m/cd55e5c5b8d528ea81c758f5f61fb7360b4c2b0e.png)
android日历毕业设计Android日历毕业设计随着智能手机的普及,人们对于日历应用的需求也越来越高。
为了满足用户对于日程管理的需求,我选择了开发一款Android日历应用作为我的毕业设计。
1. 介绍我设计的Android日历应用旨在帮助用户高效地管理日程安排,提醒重要事件,并提供个性化的用户体验。
通过使用这款应用,用户可以轻松地查看日历、添加日程、设置提醒等功能。
2. 功能设计2.1 日历视图应用的主界面是一个日历视图,用户可以通过左右滑动切换月份,点击日期可以查看当天的日程安排。
为了方便用户查看,我设计了不同的标记颜色,用于区分不同类型的事件。
2.2 添加日程用户可以通过点击日历视图上的日期,进入添加日程页面。
在页面上,用户可以输入事件的标题、日期、时间、地点等信息,并可以选择是否设置提醒。
用户还可以为事件添加标签,以便更好地分类和搜索。
2.3 提醒功能为了确保用户不会错过重要事件,我设计了提醒功能。
用户可以在添加日程时选择是否设置提醒,并可以设置提醒的时间和方式。
当事件即将发生时,应用会通过通知栏或者弹窗的方式提醒用户。
2.4 搜索功能为了方便用户查找特定的事件,我添加了搜索功能。
用户可以输入关键字,应用会根据关键字在日程中进行匹配,并将匹配的结果展示给用户。
这样,用户可以快速找到需要的信息。
2.5 多用户支持为了满足不同用户的需求,我设计了多用户支持功能。
用户可以创建自己的账户,并可以设置个人信息、头像等。
每个用户都有自己的日程安排,互不干扰。
3. 技术实现为了实现这款Android日历应用,我使用了Java语言和Android开发框架。
我采用了MVC(Model-View-Controller)的架构模式,将数据、界面和业务逻辑进行分离。
在数据层,我使用了SQLite数据库来存储用户的日程信息。
通过使用数据库,我可以方便地对数据进行增删改查操作。
在界面层,我使用了Android的布局和控件来构建用户界面。
日历源代码
![日历源代码](https://img.taocdn.com/s3/m/55ab63140740be1e650e9ac5.png)
import java.awt.BorderLayout;import java.awt.Color;import java.awt.Graphics;import java.util.Date;import java.awt.event.*;import javax.swing.*;import javax.swing.border.TitledBorder;import java.util.*;import javax.swing.JPanel;import javax.swing.JTextField;import java.awt.GridLayout;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.SwingUtilities;import javax.swing.UIManager;public class Test extends JFrame{private static final long serialVersionUID = 1L;//测试public Test(){Clock clock =new Clock();Calender cal = new Calender();@SuppressWarnings("unused")JPanel jp2 = new JPanel();setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(560,300);setVisible(true);this.setContentPane(clock);this.getContentPane().add(cal,BorderLayout.WEST); setResizable(false);}//画时钟public class DrawClock extends JPanel implements Runnable {private static final long serialVersionUID = 1L;Thread newThread; //线程public int RADIUS = 80; //时钟的半径//设置时钟位置public int centerX = 150; //设置时钟x轴public int centerY = 120; //设置时钟y轴public int hr, min, sec; //小时,分钟,秒public int[] xPoint = new int[4]; //指针的4个坐标public int[] yPoint = new int[4];public double hrAlpha, minAlpha, secAlpha, theta;private JTextField timeZone;//启动时钟public void start(){newThread = new Thread(this);newThread.start(); //启动线程}//终止线程public void stop(){newThread = null;}@SuppressWarnings("deprecation")public void paint(Graphics g){super.paint(g);//画出时钟刻度double minuteAlpha = Math.PI/30.0;int count = 0;for(double alpha=0; alpha<2.0*Math.PI; alpha+=minuteAlpha){int tX = (int)(centerX+RADIUS*0.9*Math.sin(alpha));int tY = (int)(centerY-RADIUS*0.9*Math.cos(alpha));if(count%5 == 0){g.setColor(Color.CYAN);g.fill3DRect(tX, tY, 3, 3, false);if(count%3==0){int m = count /15;switch(m){case 1: g.drawString("3", centerX+RADIUS-18, centerY+5);break;case 2: g.drawString("6", centerX-3, centerY+RADIUS-10);break;case 3: g.drawString("9", centerX-RADIUS+11,centerY+6);break;default: g.drawString("12", centerX-5, centerY-RADIUS+22);}}}else{g.setColor(Color.DARK_GRAY);g.fill3DRect(tX, tY, 2, 2, false);}count++;}//画出时钟时针g.setColor(Color.gray); // 定义颜色drawPointer(g, centerX+2, centerY+2, (int)(RADIUS*0.75), hrAlpha);g.setColor(Color.CYAN); // 定义颜色drawPointer(g, centerX, centerY, (int)(RADIUS*0.75), hrAlpha);//画出分针g.setColor(Color.gray); // 定义颜色drawPointer(g, centerX+2, centerY+2, (int)(RADIUS*0.83), minAlpha);g.setColor(Color.CYAN); // 定义颜色drawPointer(g, centerX, centerY, (int)(RADIUS*0.83), minAlpha);//画出秒针g.setColor(Color.DARK_GRAY); //定义颜色g.drawLine( centerX,centerY,(int)(centerX+(int)(RADIUS*0.79)*Math.sin(secAlpha)),(int)(centerY-(int)(RADIUS*0.79)*Math.cos(secAlpha)) );setBorder(new TitledBorder("时间"));setBackground(Color.white); // 定义颜色g.drawRect(85, 210, 130, 20);g.setColor(Color.WHITE);g.setColor(Color.DARK_GRAY);Date timeNow = new Date();g.drawString(timeNow.toLocaleString(), 100,225);}public Date getDate(){Date timeNow = new Date();return timeNow;}// 刷新图层public void update(Graphics g){paint(g);}// 画出一个帧的图像public void run() {while(newThread != null){repaint();try{Thread.sleep(800);} catch(InterruptedException E) {}Date timeNow = new Date();@SuppressWarnings("deprecation")int hours = timeNow.getHours(); //这里不知道为什么会画横线的@SuppressWarnings("deprecation")int minutes = timeNow.getMinutes(); //这里不知道为什么会画横线的@SuppressWarnings("deprecation")int seconds = timeNow.getSeconds(); //这里不知道为什么会画横线的hr = hours;min = minutes;sec = seconds;theta = Math.PI/6.0/20.0;hrAlpha = (double)(hr*3600 + min*60 + sec) /(12.0*3600.0)*2.0*Math.PI;minAlpha = (double)(min*60 + sec)/3600.0*2.0*Math.PI;secAlpha = (double)sec/60.0 * 2.0*Math.PI;}}private void drawPointer(Graphics g, int x, int y,int len, double theta){xPoint[0] = (int)(x+len*0.3*Math.sin(theta-Math.PI));yPoint[0] = (int)(y-len*0.3*Math.cos(theta-Math.PI));xPoint[1] = (int)(xPoint[0]+len*0.3*Math.sin(theta-(double)(10.0/180)*Math.PI));yPoint[1] = (int)(yPoint[0]-len*0.3*Math.cos(theta-(double)(10.0/180)*Math.PI));xPoint[2] = (int)(xPoint[0]+len * Math.sin(theta));yPoint[2] = (int)(yPoint[0]-len * Math.cos(theta));xPoint[3] = (int)(xPoint[0]+len*0.3*Math.sin(theta+(double)(10.0/180)*Math.PI));yPoint[3] = (int)(yPoint[0]-len*0.3*Math.cos(theta+(double)(10.0/180)*Math.PI));g.fillPolygon(xPoint, yPoint, 4);}public JTextField getTimeZone() {return timeZone;}public void setTimeZone(JTextField timeZone) {this.timeZone = timeZone;}}//时钟public class Clock extends JPanel{private static final long serialVersionUID = 1L;private UIManager.LookAndFeelInfo looks[];private DrawClock clock ;@SuppressWarnings("unused")private JPanel pane_clock ;JPanel pane_cal;public Clock(){super();looks = UIManager.getInstalledLookAndFeels();changeTheLookAndFeel(2);clock = new DrawClock();clock.start();this.setBackground(Color.GRAY);this.setLayout(new BorderLayout());this.setOpaque(false);this.add(clock);this.setBorder(new TitledBorder("时间日期"));setSize( 300, 300 );setVisible( true );}private void changeTheLookAndFeel(int i){try{UIManager.setLookAndFeel(looks[i].getClassName());SwingUtilities.updateComponentTreeUI(this);}catch(Exception exception){exception.printStackTrace();}}} //设计日历public class Calender extends JPanel implements ActionListener {private static final long serialVersionUID = 1L;public final String HOUR_OF_DAY = null;//定义@SuppressWarnings("rawtypes")JComboBox Month = new JComboBox();@SuppressWarnings("rawtypes")JComboBox Year = new JComboBox();JLabel Year_l = new JLabel("年");JLabel Month_l = new JLabel("月");Date now_date = new Date();JLabel[] Label_day = new JLabel[49];@SuppressWarnings("deprecation")int now_year = now_date.getYear() + 1900;@SuppressWarnings("deprecation")int now_month = now_date.getMonth(); boolean bool = false;String year_int = null;int month_int;JPanel pane_ym = new JPanel();JPanel pane_day = new JPanel();@SuppressWarnings("unchecked")public Calender(){super();//设定年月for (int i = now_year - 10; i <= now_year + 20; i++) {Year.addItem(i + "");}for (int i = 1; i < 13; i++){Month.addItem(i + "");}Year.setSelectedIndex(10);pane_ym.add(new JLabel(""));pane_ym.add(Year);pane_ym.add(Year_l);Month.setSelectedIndex(now_month);pane_ym.add(Month);pane_ym.add(Month_l);pane_ym.add(new JLabel(""));Month.addActionListener(this);Year.addActionListener(this);//初始化日期并绘制pane_day.setLayout(new GridLayout(7, 7, 10, 10)); for (int i = 0; i < 49; i++) {Label_day[i] = new JLabel("");pane_day.add(Label_day[i]);this.setDay();this.setLayout(new BorderLayout());this.add(pane_day, BorderLayout.CENTER);this.add(pane_ym, BorderLayout.NORTH);this.setSize(100,200);this.setBorder(new TitledBorder("吴佳宸的日历"));setSize(300,300);}@SuppressWarnings("deprecation")void setDay(){if (bool){year_int = now_year + "";month_int = now_month;}else{year_int = Year.getSelectedItem().toString();month_int = Month.getSelectedIndex();}int year_sel = Integer.parseInt(year_int) - 1900; //获得年份值//@SuppressWarnings("deprecation")Date dt = new Date(year_sel, month_int, 1); //构造一个日期GregorianCalendar cal = new GregorianCalendar(); //创建一个Calendar实例cal.setTime(dt);String week[] = { "日", "一","二", "三", "四", "五", "六" };int day = 0;int day_week = 0;for (int i = 0; i < 7; i++) {Label_day[i].setText(week[i]);}//月份if (month_int == 0||month_int == 2 ||month_int == 4 ||month_int == 6 ||month_int == 9 ||month_int == 11){day = 31;}else if (month_int == 3 ||month_int == 5 || month_int == 7||month_int == 8 ||month_int == 10|| month_int == 1){day = 30;else{if (cal.isLeapYear(year_sel)){day = 29;}else{day = 28;}}day_week = 7 + dt.getDay();int count = 1;for (int i = day_week; i < day_week + day; count++, i++) {if (i % 7 == 0 ||i == 13||i == 20||i == 27||i == 48 ||i == 34 ||i == 41){if (i == day_week + now_date.getDate() - 1){Label_day[i].setForeground(Color.blue);Label_day[i].setText(count + "");}else{Label_day[i].setForeground(Color.red);Label_day[i].setText(count + "");}}else{if (i == day_week + now_date.getDate() - 1){Label_day[i].setForeground(Color.blue);Label_day[i].setText(count + "");}else{Label_day[i].setForeground(Color.black);Label_day[i].setText(count + "");}}if (day_week == 0){for (int i = day; i < 49; i++){Label_day[i].setText("");}}else{for (int i = 7; i < day_week; i++){Label_day[i].setText("");}for (int i = day_week + day; i < 49; i++){Label_day[i].setText("");}}}public void actionPerformed(ActionEvent e) {if (e.getSource() == Year || e.getSource() == Month) { bool = false;this.setDay();}}}public static void main(String[] args){try{Test frame = new Test();frame.setTitle("吴佳宸的日历");}catch (Exception e){System.out.print("run error!");}}}。
C++实现万年历源代码
![C++实现万年历源代码](https://img.taocdn.com/s3/m/6d875f7426d3240c844769eae009581b6ad9bd55.png)
C++实现万年历源代码本⽂实例为⼤家分享了C++实现万年历的具体代码,供⼤家参考,具体内容如下#include<iostream>#include<string>#include<fstream>#include<iomanip>using namespace std;#include<time.h>ofstream fout("⽇历.txt");void Printtitle(int n);int OrEndl(int n);string Choose(); //选择功能int Calculate(int mon,int day);void Printday(int a);void FirstDay(int wday);void SomeYear(int p);void ThisMonth(); //打印当⽉⽇历的主函数void PrintFirstNum(int mon);void Printyear(int year);void ThisYear(int p); //打印当年⽇历的主函数void Month(int n);void Printnum(int q,int mon);int Firstwday[12]; //储存每个⽉1号的星期数struct tm *local;string ch;int a[12]={31,28,31,30,31,30,31,31,30,31,30,31}; //储存每⽉的天数int main(void){long t;time(&t);local=localtime(&t);local->tm_year=local->tm_year+1900;local->tm_mon++;cout<<"今天是:"<<local->tm_year<<"年"<<local->tm_mon<<"⽉"<<local->tm_mday<<"⽇,";fout<<"今天是:"<<local->tm_year<<"年"<<local->tm_mon<<"⽉"<<local->tm_mday<<"⽇,";Month(local->tm_wday);cout<<endl;fout<<endl;cout<<"当前时间是:"<<local->tm_hour<<"时"<<local->tm_min<<"分"<<local->tm_sec<<"秒"<<local->tm_wday<<endl;fout<<"当前时间是:"<<local->tm_hour<<"时"<<local->tm_min<<"分"<<local->tm_sec<<"秒"<<local->tm_wday<<endl;string flag;int sum;if(((local->tm_year%4==0)&&(local->tm_year%100!=0))||(local->tm_year%400==0))a[1]=29;sum=Calculate(local->tm_mon,local->tm_mday);int p=sum-(local->tm_wday+1)-(sum/7)*7;do{flag=Choose();if(flag=="1") //根据选择的数字确定调⽤哪个函数ThisMonth();else if(flag=="2")ThisYear(p);else if(flag=="3")SomeYear(p);else if(flag=="4")break;else{cout<<"输⼊错误"<<endl;fout<<"输⼊错误"<<endl;continue;}}while(1);cout<<"请选择"<<"1、当⽉⽇历"<<endl<<" 2、当年⽇历"<<endl <<" 3、万年历"<<endl<<" 4、退出"<<endl;fout<<"请选择"<<"1、当⽉⽇历"<<endl<<" 2、当年⽇历"<<endl <<" 3、万年历"<<endl<<" 4、退出"<<endl;cin>>ch;fout<<ch;cout<<endl;fout<<endl;return ch;}void ThisMonth(){int m=local->tm_mon%12;Printtitle(m);int p=local->tm_mday-(local->tm_wday+1)-(local->tm_mday/7)*7; Printnum(p,local->tm_mon);}void ThisYear(int p){FirstDay(p);Printyear(local->tm_year);for(int a=1;a<12;a=a+2){Printtitle(a);PrintFirstNum(a);}}void SomeYear(int p) //打印万年历的主函数{int m;cout<<"Please enter a year number"<<endl;fout<<"Please enter a year number"<<endl;while(1){scanf("%d",&m);if( m<0 ){printf("\nInput error,Please enter a year number again:\n");fflush(stdin); //没加这句话会死循环,加了就ok}else break;}fout<<m;cout<<endl;fout<<endl;Printyear(m);int n=m;if(n<local->tm_year) //计算所输年份的1⽉1⽇星期⼏{for(;n<local->tm_year;n++){if(((n%4==0)&&(n%100!=0))||(n%400==0))p=p+2;elsep++;if(p>=7)p=p-7;}}else{for(;n>local->tm_year;n--){if(((n%4==0)&&(n%100!=0))||(n%400==0))p=p-2;elsep--;if(p<0)for(int h=1;h<12;h=h+2){Printtitle(h);if(((m%4==0)&&(m%100!=0))||(m%400==0))a[1]=29;elsea[1]=28;PrintFirstNum(h);}}void Printtitle(int n) //打印标题{do{cout<<" ";fout<<" ";char str[12][10]={"January","February","March","April","May","June","July","August","September","October","November","December"}; for(int h=0;h<10;h++){cout<<str[n-1][h];fout<<str[n-1][h];}cout<<" ";fout<<" ";if(OrEndl(n))break;n++;}while(!(n%2));do{cout<<"____________________________";fout<<"____________________________";if(OrEndl(n))break;n++;}while(!(n%2));do{cout<<" Sun Mon Tue Wed Thu Fri Sat ";fout<<" Sun Mon Tue Wed Thu Fri Sat ";if(OrEndl(n))break;n++;}while(!(n%2));}int Calculate(int mon,int day) //计算当天到当年1⽉1⽇的天数{int sum=day;for(mon--;mon!=0;mon--)sum=sum+a[mon-1];return sum;}void FirstDay(int wday) //推算每个⽉1号的星期数{if(wday<=0)wday=wday+7;Firstwday[0]=7-wday;for(int n=0;n<11;n++){Firstwday[n+1]= Firstwday[n]+a[n]%7;if(Firstwday[n+1]>6)Firstwday[n+1]=Firstwday[n+1]-7;}}int OrEndl(int n){if(ch=="1") //如果是打出当⽉⽇历就直接跳出循环{cout<<endl;fout<<endl;return 1;fout<<" ";}else{cout<<endl;fout<<endl;}return 0;}void Printyear(int year) //打印年份{int m=year/1000;int n=(year/100)%10;int p=(year/10)%10;int q=year%10;int num[4]={m,n,p,q};char str[5][10][7]={"***** "," * ","***** ","***** ","* * ","***** ","***** ","***** ","***** ","***** ", "* * "," * "," * "," * ","* * ","* ","* "," * ","* * ","* * ","* * "," * ","***** ","***** ","***** ","***** ","***** "," * ","***** ","***** ","* * "," * ","* "," * "," * "," * ","* * "," * ","* * "," * ","***** "," * ","***** ","***** "," * ","***** ","***** "," * ","***** ","***** ",};for(int g=0;g<5;g++){cout<<" ";fout<<" ";for(int i=0;i<4;i++)for(int h=0;h<7;h++){cout<<str[g][num[i]][h];fout<<str[g][num[i]][h];}cout<<endl;fout<<endl;}}void PrintFirstNum(int mon) //打印每两个⽉的⽇历{int mday[2]; //储存每两个⽉当前打印的⽇期do{int k=0;for(;k<Firstwday[mon-1];k++){ cout<<" ";fout<<" ";}k++;for(int d=1;k<8;d++,k++) //输⼊每个⽉的第⼀⾏{cout<<" "<<d<<" ";fout<<" "<<d<<" ";}if(mon%2) //判断单⽉输空格,双⽉回车{cout<<" ";fout<<" ";mday[mon%2-1]=d;}else{cout<<endl;fout<<endl;mday[mon%2+1]=d-1;}mon++;}while(!(mon%2));mon=mon-2;int i=0,k=1,m=mon-1;for(;mday[i]<a[m]+1;mday[i]++,k++){if(mday[i]<10){{cout<<" "<<mday[i]<<" ";fout<<" "<<mday[i]<<" ";}if(k==7){if(!i){cout<<" ";fout<<" ";i=1;m++;}else{cout<<endl;fout<<endl;i=0;m--;}k=0;}}m=mon-1;if(mday[0]==a[m]+1&&mday[1]<a[m+1]+1) //当双⽉未结束,单⽉输⼊结束跳出时最后⼀⾏的输出情况 {for(;k<8;k++){cout<<" ";fout<<" ";}cout<<" ";fout<<" ";k=1;for(mday[1]++;mday[1]<a[m+1]+1;mday[1]++,k++){cout<<" "<<mday[1]<<" ";fout<<" "<<mday[1]<<" ";if(k==7){cout<<endl;fout<<endl;cout<<" ";fout<<" ";}}cout<<endl;fout<<endl;}if(mday[0]<a[m]+1&&mday[1]==a[m+1]+1) //当单⽉未结束,双⽉输⼊结束跳出时最后⼀⾏的输出情况 {cout<<endl;fout<<endl;k=1;for(mday[0]++;mday[0]<a[m]+1;mday[0]++,k++){cout<<" "<<mday[0]<<" ";fout<<" "<<mday[0]<<" ";if(k==7){cout<<endl;fout<<endl;cout<<" ";fout<<" ";}}cout<<endl;fout<<endl;}}void Month(int n)cout<<str[n][h];fout<<str[n][h];}}void Printnum(int q,int mon) //打印当⽉⽇历{if(q<0)q=q+7;int k=0;if(q!=7&&q){for(;k<7-q;k++){cout<<" ";fout<<" ";}}k++;for(int d=1;d<a[mon-1]+1;d++,k++){cout<<setw(4)<<d;if(k==7){cout<<endl;fout<<endl;k=0;}}cout<<endl;fout<<endl;}以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
万年历源代码
![万年历源代码](https://img.taocdn.com/s3/m/ba5df94469eae009581bec50.png)
if(sum<=213&&sum>182)
printf("七月%d号\n",sum-182);
if(sum<=244&&sum>213)
printf("八月%d号\n",sum-213);
printf("请输入日期 (year-month-day) n:\n");printf("例如:2011-06-20 6\n");
scanf("%d-%d-%d%d",&yr,&mn,&day,&n);
if((0==yr%4 && 0!=yr%100)||0==yr%400)
switch(option)
{
case 1:
while(1)
{
int flag=1;
char time[128];
_strtime(time);
printf( "当前系统时间:%s\n",time);
printf("\ndo you want to continue?(Y/N)");
scanf("%d",&year);
if(IsLeapYear(year))
printf("\n%d是闰年,do you want to continue?(Y/N)",year);
else
printf("\n%d 不是闰年,do you want to continue(Y/N)?",year);
日历代码
![日历代码](https://img.taocdn.com/s3/m/b5ac0e4d69eae009581becae.png)
{
//如果月份为奇数月,则天数有31天
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days=31;
break;
//当月份为2月时
case 2:
int year,month;//接受用户输入的年、月。。。
//提示用户输入年份
printf("请输入日期(如:2013或2013-05):");
//接收用户输入的年份
scanf("%d-%d",&year,&month);
//判断用户输入的月份是否在1月到12月之间,如果不是,则提示用户重新输入,直到用户输入的年份符合要求
int firstdayofmonth;//代表一个月的第一天
int a;//代表一个月的第几天
//循环产生年份,初始年份为1940年,最大年份为用户输入的年份
for(int i=1940;i<year;i++)
{
//判断年份是否为闰年或平年
if(i%4==0 && i%100!=0 || i%400==0)
{
printf("\n");//如果当天是星期六,输出换行
}
}
}
void main()
{
printf(" ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n");
printf("☆■■■■■■■■日■■历■■■■■■■■☆\n");
实现基于Android的日历系统
![实现基于Android的日历系统](https://img.taocdn.com/s3/m/f7b1e9140b4e767f5acfcefa.png)
实用第一智慧密集2011.05实现基于Android 的日历系统李宁1引言要实现的日历除了常规的日历功能外,还可以显示与当前日期相关的信息,如当前日期的农历日期、天干地支、节日等信息。
下面先看看日历的绚丽界面,如图1、图2所示。
2绘画基础由于实现的日历系统要涉及到大量的Android 绘图技术,因此,要简单介绍Android 的绘图技术。
绘制图形通常在Android.view.View 或其子类的onDraw 方法中进行。
该方法的定义如下:protected void onDraw(Canvas canvas);其中Canvas 对象提供了大量用于绘图的方法,这些方法主要包括绘制像素点、直线、圆形、弧、文本,这些都是组成复杂图形的基本元素。
如果要画更复杂的图形,可以采用组合这些图形基本元素的方式来完成。
例如,可以采用画3条直线的方式来画三角形。
下面来看一下绘制图形基本元素的方法。
2.1绘制像素点public native void drawPoint(float x,float y,Paint paint);//画一个像素点public native void drawPoints(float[]pts,int offset,int count,Paint paint);//画多个像素点public void drawPoints(float[]pts,Paint paint);//画多个像素点参数的含义如下:(1)x :像素点的横坐标。
(2)y :像素点的纵坐标。
(3)paint :描述像素点属性的Paint 对象。
可设置像素点的大小、颜色等属性。
绘制其他图形元素的Paint 对象与绘制像素点的Paint 对象的含义相同。
在绘制具体的图形元素时可根据实际的情况设置Paint 对象。
(4)pts :drawPoints 方法可一次性画多个像素点。
pts 参数表示多个像素点的坐标。
该数组元素必须是偶数个,两个一组为一个像素点的坐标。
日历程序代码
![日历程序代码](https://img.taocdn.com/s3/m/90ed907531b765ce0408140d.png)
}
}
void main()
{
init();
while(1)//大循环
{
keyscan();
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
write_com(0x06);//显示光标移动设置,光标左移
write_com(0x01);//显示清屏
write_com(0x80);//第一行命令的地址指针
for(num=0;num<14;num++)
{
write_date(table[num]);
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{
uchar num;
dula=0;
wela=0;
lcden=0;
write_com(0x38);//写指令开启1602
write_com(0x0c);//显示开及光标设置(不显示光标)
delay(5);
}
TMOD=0x01;//定时器0开启方式1
TH0=(65536-50000)/256;//定时一秒高四位
TL0=(65536-50000)%256;//定时一秒低四位
EA=1;//开总中断
ET0=1;//开定时器0中断
TR0=1;//启动定时器0
{
if(nian==100)
日历代码(VB实现)
![日历代码(VB实现)](https://img.taocdn.com/s3/m/cfb2ec3f0b4c2e3f572763b3.png)
日历设计VB实现最终效果如下:设计过程界面如下:Private Sub Combo1_Click()Picture1.Clsnian = Val(Combo1.Text)yue = Val(Combo2.Text)i = 0: j = 0: Sum = 0Dim y As IntegerFor y = 1900 To nian - 1If f(y) = 1 Theni = i + 1Elsej = j + 1End IfNext ySum = Sum + i * 366 + j * 365For i = 1 To yue - 1Sum = Sum + tian(nian, i)Next iDim a As Datea = #1/1/1900# + SumPicture1.Print "今天日期:"; Year(Date); "年"; Month(Date); "月"; Day(Date); "日"Picture1.PrintPicture1.Print " 日"; Tab(9); "一"; Tab(17); "二"; Tab(25); "三"; Tab(33); "四"; Tab(41); "五"; Tab(49); "六"n = Weekday(a)m = 0k = 0For i = 1 To 8 - nPicture1.Print Tab(8 * (i + n - 2)); i;Next iPicture1.PrintFor i = 9 - n To tian(nian, yue)Picture1.Print i; Tab(8 * (i + n - 8 - k));m = m + 1If m Mod 7 = 0 Then k = k + 7: Picture1.PrintNext iEnd SubPrivate Sub Combo2_Click()Picture1.Clsnian = Val(Combo1.Text)yue = Val(Combo2.Text)i = 0: j = 0: Sum = 0Dim y As IntegerFor y = 1900 To nian - 1If f(y) = 1 Theni = i + 1Elsej = j + 1Next ySum = Sum + i * 366 + j * 365For i = 1 To yue - 1Sum = Sum + tian(nian, i)Next iDim a As Datea = #1/1/1900# + SumPicture1.Print "今天日期:"; Year(Date); "年"; Month(Date); "月"; Day(Date); "日"Picture1.PrintPicture1.Print " 日"; Tab(9); "一"; Tab(17); "二"; Tab(25); "三"; Tab(33); "四"; Tab(41); "五"; Tab(49); "六"n = Weekday(a)m = 0k = 0For i = 1 To 8 - nPicture1.Print Tab(8 * (i + n - 2)); i;Next iPicture1.PrintFor i = 9 - n To tian(nian, yue)Picture1.Print i; Tab(8 * (i + n - 8 - k));m = m + 1If m Mod 7 = 0 Then k = k + 7: Picture1.PrintNext iEnd SubPrivate Sub Form_Load()ShowLabel3.Caption = "现在时间:" + Str(Time)For i = 1900 To 2100Combo1.AddItem (i)Next iCombo1.Text = Combo1.List(Year(Date) - 1900)Combo2.Text = Combo2.List(Month(Date) - 1)Picture1.Clsnian = Year(Date)yue = Month(Date)i = 0: j = 0: Sum = 0Dim y As IntegerFor y = 1900 To nian - 1If f(y) = 1 Theni = i + 1Elsej = j + 1Next ySum = Sum + i * 366 + j * 365For i = 1 To yue - 1Sum = Sum + tian(nian, i)Next iDim a As Datea = #1/1/1900# + SumPicture1.Print " 今天日期:"; nian; "年"; yue; "月"; Day(Date); "日"Picture1.PrintPicture1.Print " 日"; Tab(9); "一"; Tab(17); "二"; Tab(25); "三"; Tab(33); "四"; Tab(41); "五"; Tab(49); "六"n = Weekday(a)m = 0k = 0For i = 1 To 8 - nPicture1.Print Tab(8 * (i + n - 2)); i;Next iPicture1.PrintFor i = 9 - n To tian(nian, yue)Picture1.Print i; Tab(8 * (i + n - 8 - k));m = m + 1If m Mod 7 = 0 Then k = k + 7: Picture1.PrintNext iEnd SubFunction f(y As Integer) As IntegerIf (y Mod 4 = 0 And y Mod 100 <> 0 Or y Mod 400 = 0) Thenf = 1Elsef = 0End IfEnd FunctionFunction tian(nian, yue)Dim t As Stringt = ""Select Case yueCase 1, 3, 5, 7, 8, 10, 12tian = 31Case 4, 6, 9, 11tian = 30Case 2If (nian Mod 4 = 0 And nian Mod 100 <> 0 Or nian Mod 400 = 0) Thentian = 29Elsetian = 28End IfEnd SelectEnd FunctionPrivate Sub Label3_Click()End SubPrivate Sub Timer1_Timer()Label3.Caption = "现在时间:" + Str(Time) End Sub。
万年历代码c语言
![万年历代码c语言](https://img.taocdn.com/s3/m/d0260a62ae45b307e87101f69e3143323968f5c3.png)
万年历代码c语言万年历是一种实用的日历工具,它可以根据年、月、日来显示当天的日期信息,并可以切换到其他日期来查询对应的日期信息。
在编写万年历的代码时,我们需要考虑输入的年份是否为闰年、每个月的天数、以及每个月第一天是星期几等等。
以下是一份使用C语言编写万年历的参考代码:```c#include <stdio.h>// 判断是否为闰年int isLeapYear(int year) {return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); }// 获取某年某月的天数int getMonthDays(int year, int month) {int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};if (month == 2 && isLeapYear(year)) {return 29;}return days[month - 1];}// 获取某年某月第一天是星期几int getFirstDayOfWeek(int year, int month) {int day = 1;for (int i = 1800; i < year; i++) {if (isLeapYear(i)) {day = (day + 366) % 7;} else {day = (day + 365) % 7;}}for (int i = 1; i < month; i++) {day = (day + getMonthDays(year, i)) % 7;}return day;}int main() {int year, month;printf("请输入年份:");scanf("%d", &year);printf("请输入月份:");scanf("%d", &month);// 判断输入是否合法if (year < 1800 || month < 1 || month > 12) {printf("输入的年份或月份不合法!\n");return 0;}// 获取某年某月的天数和第一天是星期几int days = getMonthDays(year, month);int firstDayOfWeek = getFirstDayOfWeek(year, month); // 打印万年历printf("日一二三四五六\n");for (int i = 0; i < firstDayOfWeek; i++) {printf(" ");}for (int i = 1; i <= days; i++) {printf("%2d ", i);if ((firstDayOfWeek + i) % 7 == 0) {printf("\n");}}printf("\n");return 0;}```以上代码实现了一个简单的万年历功能,在控制台输出给定年份和月份的月历。
万年历源代码
![万年历源代码](https://img.taocdn.com/s3/m/f99675a2284ac850ad024251.png)
printf("六月%d号\n",sum-152);
if(sum<=213&&sum>182)
printf("七月%d号\n",sum-182);
if(sum<=244&&sum>213)
if(sum<=243&&sum>212)
printf("八月%d号\n",sum-212);
if(sum<=273&&sum>243)
printf("九月%d号\n",sum-243);
if(sum<=304&&sum>273)
case 5: printf("星期六\n"); break;
case 6: printf("星期日\n"); break;
}
};break;
case 3://输入变量是3时,先判断此日期是星期几,在计算n天后是星期几
{
printf("请输入日期和天数:\n格式为:1900,1,1;n\n");
if(sum<=335&&sum>305)
printf("十一月%d号\n",sum-305);
if(sum<=366&&sum>335)
printf("十二月%d号\n",sum-335);
}
};break;
timenow = localtime ( &T );
安卓日历开发源代码
![安卓日历开发源代码](https://img.taocdn.com/s3/m/bc0dc6cd9a89680203d8ce2f0066f5335a8167ef.png)
安卓日历开发源代码<="" p="" xmlns:android="/res/android"> android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" ><linearlayout< p="">android:id="@+id/lay_title"style="@style/TitleStyle"android:layout_width="fill_parent" ><textview< p="">android:id="@+id/btn_back"style="@style/TitleLeftButtonStyle" /><textview< p="">android:id="@+id/tv_top"style="@style/TitleMiddleTextStyle" android:text="请选择日期" /><textview< p="">android:id="@+id/btn_goback_to_today" style="@style/TitleRightButtonStyle" android:text="今天" /></textview<></textview<></textview<></linearlayout<><linearlayout< p="">android:layout_width="fill_parent" android:layout_height="53.0dip" android:background="#ff394147" android:gravity="center_vertical" ><linearlayout< p="">android:id="@+id/btn_prev_month"android:layout_width="0.0dip"android:layout_height="fill_parent"android:layout_weight="0.2"android:gravity="center"android:orientation="vertical" ><textview< p="">android:id="@+id/left_img"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/triangle06_states" android:duplicateParentState="true"android:text=""android:textSize="16.0dip" /></textview<></linearlayout<></linearlayout<>。
原生JS实现日历组件的示例代码
![原生JS实现日历组件的示例代码](https://img.taocdn.com/s3/m/0fd8b1e5bb0d4a7302768e9951e79b896802681b.png)
原⽣JS实现⽇历组件的⽰例代码想要实现的效果点击⽇期选择框出现⽇历有个⽇期控制栏帮助选择⽇期,包括年、⽉、⽇的选择和今天⽇历格⼦,初次点击⽇期选择框时显⽰此刻的⽇期,⽇历格⼦的⽇期应该包括这个⽉的所有天数,同时如果当⽉的1号不是周⽇,还应补全从周⽇到1号的天数。
还要在这个⽉最后1号的后⾯补全到周六。
⽇期控制栏和⽇历格⼦的⽇期还有选择框⾥的⽇期的变化要是同步的。
实现思路为了组件的可复⽤性,需要⽤⾯向对象的思想。
每个⽇历组件都是⼀个⽇历对象,主要包括⽇期选择框,⽇期控制显⽰栏,还有⽇历格⼦,为了保持⽇期控制显⽰栏和⽇历格⼦⽇期同步变化,⽇期控制栏和⽇历⾥⾯的每个格⼦都应该包含⼀个Date属性,点击⽇历⾥的格⼦,将格⼦存的Date属性作为函数参数,调⽤函数改变⽇期控制栏显⽰的时间。
同理,⽇期控制栏时间变化时,也将Date属性作为参数调⽤函数,函数重新绘制⽇历格⼦。
上码:function Calendar(parentId) {this.parentElement = document.getElementById(parentId);this.init();}Calendar.prototype = {init: function() {this.contains = document.createElement("div");this.contains.onselectstart = function(){return false}; //让按钮点击时不会出现⽂字被选中的蓝⾊块this.dateInput = document.createElement("input");this.datePicker = document.createElement("div");this.showDateBar = document.createElement("div");this.dateBox = document.createElement("div");this.icon = document.createElement("i");this.contains.className = 'datepicker-container';this.dateInput.className = 'date-input';this.dateInput.readOnly = true;var parent = this;this.dateInput.onclick = function(event){parent.onDateInputClick(event); //点击⽇期选择框时显⽰⽇历格⼦};this.contains.onblur = function(){parent.datePicker.style.display = 'none';}this.datePicker.className = 'date-picker';this.datePicker.style.display = 'none';this.showDateBar.className = 'show-date';this.dateBox.className = 'date-box';this.icon.className = 'date-icon';this.icon.innerHTML = ' '; //iconfont这⾥⽤的阿⾥图标,可以⾃⾏替换this.datePicker.appendChild(this.showDateBar);this.datePicker.appendChild(this.dateBox);this.contains.appendChild(this.dateInput);this.contains.appendChild(this.icon);this.contains.appendChild(this.datePicker);this.parentElement.appendChild(this.contains);},}初始化⽇期控制栏:drawShowDateBar: function(parentElement){var parent = this;var nowDate = new Date();parentElement.date = nowDate;var nowYear = nowDate.getFullYear();var nowMonth = nowDate.getMonth();var nowDay = nowDate.getDate();//showDateBar内容拼接var contentStr ='<div class="year-input"><span>'+nowYear+'年</span><i class="select-year-btn"> </i><ul class="year-select-box" style="display : none">'; for(var i=0;i<150;i++){contentStr+='<li>'+(i+1900)+'年</li>';}contentStr+='</ul></div>'+'<div class="month-input"><i class="prev-month"> </i><select class="months-options">'for(var i=0;i<12;i++){contentStr+='<option>'+(i+1)+'⽉</option>';}contentStr+='</select><i class="next-month"> </i></div>'+'<div class="day-input"><i class="prev-day"> </i><select class="days-options"></select>'+'<i class="next-day"> </i></div>'+'<button class="today-btn">今天</button>'+'<div class="days-title">';var weekday = ['⽇', '⼀', '⼆', '三', '四', '五', '六'];for (var i = 0; i < 7; i++) {contentStr+='<span class="day-title">'+weekday[i]+'</span>';}contentStr+='</div>';parentElement.innerHTML = contentStr;this.changeShowDateBar(nowDate); //插⼊到showTimeBar之后,初始化,传⼊的参数是现在的时间var yearInput = parentElement.firstChild;//年选择框点击显⽰和隐藏选择列表yearInput.onclick = function(){ //target和this的区别 target是触发事件的元素,this是处理事件的元素var ul = stChild;ul.style.display==='none'||ul.style.display==='none'? ul.style.display='inline-block':ul.style.display='none';};//为年选择下拉框绑定点击事件var yearSelectBox = stChild;var yearLi = yearSelectBox.children;for(var i=0;i<yearLi.length;i++){yearLi[i].onclick = function(){parent.showDateBar.date.setFullYear(this.innerText.slice(0,-1));parent.changeShowDateBar(parent.showDateBar.date); //时间改变之后都要重新调⽤,因为不同年,不同⽉,某个⽉的天数不全⼀样 };}//为month的前后按钮添加点击事件var monthInput = yearInput.nextSibling;monthInput.firstChild.onclick = function(){var monthOptions = this.nextSibling;if(monthOptions.selectedIndex>0){parent.showDateBar.date.setMonth(--monthOptions.selectedIndex);}else{monthOptions.selectedIndex = 11;parent.showDateBar.date.setFullYear(parent.showDateBar.date.getFullYear()-1);parent.showDateBar.date.setMonth(11);}parent.changeShowDateBar(parent.showDateBar.date);};stChild.onclick = function(){var monthOptions = this.previousSibling;if(monthOptions.selectedIndex<11){parent.showDateBar.date.setMonth(++monthOptions.selectedIndex);}else{monthOptions.selectedIndex = 0;parent.showDateBar.date.setFullYear(parent.showDateBar.date.getFullYear()+1);parent.showDateBar.date.setMonth(0);}parent.changeShowDateBar(parent.showDateBar.date);}monthInput.children[1].onchange = function(){parent.showDateBar.date.setMonth(this.selectedIndex);parent.changeShowDateBar(parent.showDateBar.date)};//为day的前后按钮添加点击事件var dayInput = monthInput.nextSibling;dayInput.firstChild.onclick = function(){var dayOptions = this.nextSibling;if(dayOptions.selectedIndex>0){parent.showDateBar.date.setDate(dayOptions.selectedIndex--);}else{parent.showDateBar.date.setMonth(parent.showDateBar.date.getMonth()-1);parent.showDateBar.date.setDate(parent.getDaysOfMonth(parent.showDateBar.date));}parent.changeShowDateBar(parent.showDateBar.date);};stChild.onclick = function(){var dayOptions = this.previousSibling;if(dayOptions.selectedIndex < dayOptions.length-1){dayOptions.selectedIndex++;parent.showDateBar.date.setDate(dayOptions.selectedIndex+1);}else{parent.showDateBar.date.setDate(1);parent.showDateBar.date.setMonth(parent.showDateBar.date.getMonth()+1);}parent.changeShowDateBar(parent.showDateBar.date);};dayInput.children[1].onchange = function(){parent.showDateBar.date.setDate(this.selectedIndex+1);parent.changeShowDateBar(parent.showDateBar.date)};//为今天按钮绑定点击事件var todayBtn = dayInput.nextSibling;todayBtn.onclick = function(){parent.drawPicker(new Date());parent.changeShowDateBar(new Date());}},drawShowDateBar函数为⽇期控制栏的年份、⽉份、和天的点击按钮设置了点击事件处理函数。
Android日历完整实现
![Android日历完整实现](https://img.taocdn.com/s3/m/131a4d1959eef8c75fbfb37a.png)
实用第一智慧密集2011. 05实现基于Android 的日历系统摘要: Android 作为目前较为流行的智能手机操作系统已成为大多数人的首选。
在美国乃至世界的很多地方的出货量已经超越Iphone,成为世界上最大智能手机操作系统。
因此,世界各地的程序员都跃跃欲试地想学习Android 的开发,并希望从中捞得属于自己的第一桶金。
在此给出一个基于Android 的日历系统的完整实现过程。
关键词: Android;日历;绘画;农历;记录;提醒1 引言要实现的日历除了常规的日历功能外,还可以显示与当前日期相关的信息,如当前日期的农历日期、天干地支、节日等信息。
下面先看看日历的绚丽界面,如图1、图2 所示。
主要功能2 绘画基础由于实现的日历系统要涉及到大量的Android 绘图技术,因此,要简单介绍Android 的绘图技术。
绘制图形通常在Android.view.View 或其子类的onDraw 方法中进行。
该方法的定义如下:protected void onDraw(Canvas canvas);其中Canvas 对象提供了大量用于绘图的方法,这些方法主要包括绘制像素点、直线、圆形、弧、文本,这些都是组成复杂图形的基本元素。
如果要画更复杂的图形,可以采用组合这些图形基本元素的方式来完成。
例如,可以采用画3 条直线的方式来画三角形。
下面来看一下绘制图形基本元素的方法。
2.1 绘制像素点public native void drawPoint(float x, float y, Paint paint);// 画一个像素点public native void drawPoints(float[] pts, int offset, int count, Paint paint); // 画多个像素点public void drawPoints(float[] pts, Paint paint);// 画多个像素点参数的含义如下:(1) x:像素点的横坐标。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><LinearLayoutandroid:id="@+id/lay_title"style="@style/TitleStyle"android:layout_width="fill_parent" ><TextViewandroid:id="@+id/btn_back"style="@style/TitleLeftButtonStyle" /><TextViewandroid:id="@+id/tv_top"style="@style/TitleMiddleTextStyle"android:text="请选择日期" /><TextViewandroid:id="@+id/btn_goback_to_today"style="@style/TitleRightButtonStyle"android:text="今天" /></LinearLayout><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="53.0dip"android:background="#ff394147"android:gravity="center_vertical" ><LinearLayoutandroid:id="@+id/btn_prev_month"android:layout_width="0.0dip"android:layout_height="fill_parent"android:layout_weight="0.2"android:gravity="center"android:orientation="vertical" ><TextViewandroid:id="@+id/left_img"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/triangle06_states"android:duplicateParentState="true"android:text=""android:textSize="16.0dip" /></LinearLayout><LinearLayoutandroid:layout_width="0.0dip"android:layout_height="fill_parent"android:layout_weight="0.6"android:gravity="center"android:orientation="vertical" ><TextViewandroid:id="@+id/tv_month"android:layout_width="wrap_content"android:layout_height="wrap_content"android:gravity="center"android:text="xxxx年14月"android:textColor="#ffffffff"android:textSize="21.0dip" /></LinearLayout><LinearLayoutandroid:id="@+id/btn_next_month"android:layout_width="0.0dip"android:layout_height="fill_parent"android:layout_weight="0.2"android:gravity="center"android:orientation="vertical" ><TextViewandroid:id="@+id/right_img"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/triangle05_states"android:duplicateParentState="true"android:text=""android:textSize="16.0dip" /></LinearLayout></LinearLayout><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="22.0dip"android:background="#ff8091a8" ><TextViewandroid:layout_width="0.0dip"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_weight="1.0"android:gravity="center"android:text="周日"android:textColor="#ffffffff"android:textSize="14.0dip" /><TextViewandroid:layout_width="0.0dip"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_weight="1.0"android:gravity="center"android:text="周一"android:textColor="#ffffffff"android:textSize="14.0dip" /><TextViewandroid:layout_width="0.0dip"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_weight="1.0"android:gravity="center"android:text="周二"android:textColor="#ffffffff"android:textSize="14.0dip" /><TextViewandroid:layout_width="0.0dip"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_weight="1.0"android:gravity="center"android:text="周三"android:textColor="#ffffffff"android:textSize="14.0dip" /><TextViewandroid:layout_width="0.0dip"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_weight="1.0"android:gravity="center"android:text="周四"android:textColor="#ffffffff"android:textSize="14.0dip" /><TextViewandroid:layout_width="0.0dip"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_weight="1.0"android:gravity="center"android:text="周五"android:textColor="#ffffffff"android:textSize="14.0dip" /><TextViewandroid:layout_width="0.0dip"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_weight="1.0"android:gravity="center"android:text="周六"android:textColor="#ffffffff"android:textSize="14.0dip" /></LinearLayout><GridViewandroid:id="@+id/gridview"android:layout_width="fill_parent"android:layout_height="wrap_content"android:background="#00000000"android:clickable="true"android:clipChildren="true"android:columnWidth="55.0dip"android:horizontalSpacing="1.0dip"android:listSelector="@null"android:numColumns="7"android:paddingBottom="1.0dip"android:stretchMode="columnWidth"android:verticalSpacing="1.0dip" /></LinearLayout> 】<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="/apk/res/android"android:background="#FFFFFF"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextViewandroid:gravity="center"android:layout_width="46dp"android:layout_height="55dp"android:id="@+id/tvtext"/></LinearLayout><strong><span style="font-size:32px;color:#ff0000;"></span></strong>/*** 日历gridview中的每一个item显示的textview* @author lmw**/public class CalendarAdapter extends BaseAdapter {private boolean isLeapyear = false; //是否为闰年private int daysOfMonth = 0; //某月的天数private int dayOfWeek = 0; //具体某一天是星期几private int lastDaysOfMonth = 0; //上一个月的总天数private Context context;private String[] dayNumber = new String[42]; //一个gridview中的日期存入此数组中// private static String week[] = {"周日","周一","周二","周三","周四","周五","周六"};private SpecialCalendar sc = null;private LunarCalendar lc = null;private Resources res = null;private Drawable drawable = null;private String currentYear = "";private String currentMonth = "";private String currentDay = "";private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d");private int currentFlag = -1; //用于标记当天private int[] schDateTagFlag = null; //存储当月所有的日程日期private String showYear = ""; //用于在头部显示的年份private String showMonth = ""; //用于在头部显示的月份private String animalsYear = "";private String leapMonth = ""; //闰哪一个月private String cyclical = ""; //天干地支//系统当前时间private String sysDate = "";private String sys_year = "";private String sys_month = "";private String sys_day = "";public CalendarAdapter(){Date date = new Date();sysDate = sdf.format(date); //当期日期sys_year = sysDate.split("-")[0];sys_month = sysDate.split("-")[1];sys_day = sysDate.split("-")[2];}public CalendarAdapter(Context context,Resources rs,int jumpMonth,int jumpYear,int year_c,int month_c,int day_c){this();this.context= context;sc = new SpecialCalendar();lc = new LunarCalendar();this.res = rs;int stepYear = year_c+jumpYear;int stepMonth = month_c+jumpMonth ;if(stepMonth > 0){//往下一个月滑动if(stepMonth%12 == 0){stepYear = year_c + stepMonth/12 -1;stepMonth = 12;}else{stepYear = year_c + stepMonth/12;stepMonth = stepMonth%12;}}else{//往上一个月滑动stepYear = year_c - 1 + stepMonth/12;stepMonth = stepMonth%12 + 12;if(stepMonth%12 == 0){}}currentYear = String.valueOf(stepYear);; //得到当前的年份currentMonth = String.valueOf(stepMonth); //得到本月(jumpMonth为滑动的次数,每滑动一次就增加一月或减一月)currentDay = String.valueOf(day_c); //得到当前日期是哪天getCalendar(Integer.parseInt(currentYear),Integer.parseInt(currentMonth));}public CalendarAdapter(Context context,Resources rs,int year, int month, int day){ this();this.context= context;sc = new SpecialCalendar();lc = new LunarCalendar();this.res = rs;currentYear = String.valueOf(year);; //得到跳转到的年份currentMonth = String.valueOf(month); //得到跳转到的月份currentDay = String.valueOf(day); //得到跳转到的天getCalendar(Integer.parseInt(currentYear),Integer.parseInt(currentMonth));}@Overridepublic int getCount() {// TODO Auto-generated method stubreturn dayNumber.length;}@Overridepublic Object getItem(int position) {// TODO Auto-generated method stubreturn position;}@Overridepublic long getItemId(int position) {// TODO Auto-generated method stubreturn position;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {if(convertView == null){convertView = LayoutInflater.from(context).inflate(yout.calendar_item, null);}TextView textView = (TextView) convertView.findViewById(text);String d = dayNumber[position].split("\\.")[0];String dv = dayNumber[position].split("\\.")[1];SpannableString sp = new SpannableString(d+"\n"+dv);sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, d.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);sp.setSpan(new RelativeSizeSpan(1.2f) , 0, d.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);if(dv != null ||dv != ""){sp.setSpan(new RelativeSizeSpan(0.75f), d.length()+1, dayNumber[position].length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);}// sp.setSpan(new ForegroundColorSpan(Color.MAGENTA), 14, 16, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)textView.setText(sp);textView.setTextColor(Color.GRAY);// if(position<7){// //设置周// textView.setTextColor(Color.WHITE);// textView.setBackgroundColor(color.search_txt_color);// textView.setTextSize(14);// }if (position < daysOfMonth + dayOfWeek && position >= dayOfWeek) {// 当前月信息显示textView.setTextColor(Color.BLACK);// 当月字体设黑drawable = res.getDrawable(R.drawable.current_day_bgc);}if(schDateTagFlag != null && schDateTagFlag.length >0){for(int i = 0; i < schDateTagFlag.length; i++){if(schDateTagFlag[i] == position){//设置日程标记背景textView.setBackgroundResource(R.drawable.mark);}}}if(currentFlag == position){//设置当天的背景drawable = res.getDrawable(R.drawable.current_day_bgc);textView.setBackgroundDrawable(drawable);textView.setTextColor(Color.WHITE);}return convertView;}//得到某年的某月的天数且这月的第一天是星期几public void getCalendar(int year, int month){isLeapyear = sc.isLeapYear(year); //是否为闰年daysOfMonth = sc.getDaysOfMonth(isLeapyear, month); //某月的总天数dayOfWeek = sc.getWeekdayOfMonth(year, month); //某月第一天为星期几lastDaysOfMonth = sc.getDaysOfMonth(isLeapyear, month-1); //上一个月的总天数Log.d("DAY", isLeapyear+" ====== "+daysOfMonth+" ============ "+dayOfWeek+" ========= "+lastDaysOfMonth);getweek(year,month);}//将一个月中的每一天的值添加入数组dayNuber中private void getweek(int year, int month) {int j = 1;int flag = 0;String lunarDay = "";//得到当前月的所有日程日期(这些日期需要标记)for (int i = 0; i < dayNumber.length; i++) {// 周一// if(i<7){// dayNumber[i]=week[i]+"."+" ";// }if(i < dayOfWeek){ //前一个月int temp = lastDaysOfMonth - dayOfWeek+1;lunarDay = lc.getLunarDate(year, month-1, temp+i,false);dayNumber[i] = (temp + i)+"."+lunarDay;}else if(i < daysOfMonth + dayOfWeek){ //本月String day = String.valueOf(i-dayOfWeek+1); //得到的日期lunarDay = lc.getLunarDate(year, month, i-dayOfWeek+1,false);dayNumber[i] = i-dayOfWeek+1+"."+lunarDay;//对于当前月才去标记当前日期if(sys_year.equals(String.valueOf(year)) && sys_month.equals(String.valueOf(month)) && sys_day.equals(day)){//标记当前日期currentFlag = i;}setShowYear(String.valueOf(year));setShowMonth(String.valueOf(month));setAnimalsYear(lc.animalsYear(year));setLeapMonth(lc.leapMonth == 0?"":String.valueOf(lc.leapMonth));setCyclical(lc.cyclical(year));}else{ //下一个月lunarDay = lc.getLunarDate(year, month+1, j,false);dayNumber[i] = j+"."+lunarDay;j++;}}String abc = "";for(int i = 0; i < dayNumber.length; i++){abc = abc+dayNumber[i]+":";}Log.d("DAYNUMBER",abc);}public void matchScheduleDate(int year, int month, int day){}/*** 点击每一个item时返回item中的日期* @param position* @return*/public String getDateByClickItem(int position){return dayNumber[position];}/*** 在点击gridView时,得到这个月中第一天的位置* @return*/public int getStartPositon(){return dayOfWeek+7;/*** 在点击gridView时,得到这个月中最后一天的位置* @return*/public int getEndPosition(){return (dayOfWeek+daysOfMonth+7)-1;}public String getShowYear() {return showYear;}public void setShowYear(String showYear) {this.showYear = showYear;}public String getShowMonth() {return showMonth;}public void setShowMonth(String showMonth) { this.showMonth = showMonth;}public String getAnimalsYear() {return animalsYear;}public void setAnimalsYear(String animalsYear) { this.animalsYear = animalsYear;}public String getLeapMonth() {return leapMonth;}public void setLeapMonth(String leapMonth) {this.leapMonth = leapMonth;}public String getCyclical() {return cyclical;public void setCyclical(String cyclical) {this.cyclical = cyclical;}}import java.util.Calendar;public class SpecialCalendar {private int daysOfMonth = 0; //某月的天数private int dayOfWeek = 0; //具体某一天是星期几// 判断是否为闰年public boolean isLeapYear(int year) {if (year % 100 == 0 && year % 400 == 0) {return true;} else if (year % 100 != 0 && year % 4 == 0) {return true;}return false;}//得到某月有多少天数public int getDaysOfMonth(boolean isLeapyear, int month) { switch (month) {case 1:case 3:case 5:case 7:case 8:case 10:case 12:daysOfMonth = 31;break;case 4:case 6:case 9:case 11:daysOfMonth = 30;break;case 2:if (isLeapyear) {daysOfMonth = 29;} else {daysOfMonth = 28;}}return daysOfMonth;}//指定某年中的某月的第一天是星期几public int getWeekdayOfMonth(int year, int month){Calendar cal = Calendar.getInstance();cal.set(year, month-1, 1);dayOfWeek = cal.get(Calendar.DAY_OF_WEEK)-1;return dayOfWeek;}}public class LunarCalendar {private int year; //农历的年份private int month;private int day;private String lunarMonth; //农历的月份private boolean leap;public int leapMonth = 0; //闰的是哪个月final static String chineseNumber[] = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" };static SimpleDateFormat chineseDateFormat = new SimpleDateFormat("yyyy年MM月dd日");final static long[] lunarInfo = new long[] { 0x04bd8, 0x04ae0, 0x0a570,0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2,0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0,0x0ada2, 0x095b0, 0x14977, 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50,0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, 0x06566,0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0,0x1c8d7, 0x0c950, 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4,0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 0x06ca0, 0x0b550,0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950,0x06aa0, 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260,0x0f263, 0x0d950, 0x05b57, 0x056a0, 0x096d0, 0x04dd5, 0x04ad0,0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6,0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40,0x0af46, 0x0ab60, 0x09570, 0x04af5, 0x04970, 0x064b0, 0x074a3,0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0, 0x0c960,0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0,0x092d0, 0x0cab5, 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9,0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, 0x07954, 0x06aa0,0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65,0x0d530, 0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0,0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, 0x0b5a0, 0x056d0, 0x055b2,0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0 };//农历部分假日final static String[] lunarHoliday = new String[]{"0101 春节","0115 元宵","0505 端午","0707 七夕情人","0715 中元","0815 中秋","0909 重阳","1208 腊八","1224 小年","0100 除夕"};//公历部分节假日final static String[] solarHoliday = new String[]{"0101 元旦","0214 情人","0308 妇女","0312 植树","0315 消费者权益日","0401 愚人","0501 劳动","0504 青年","0512 护士","0601 儿童","0701 建党","0801 建军","0808 父亲","0909 毛泽东逝世纪念","0910 教师","0928 孔子诞辰","1001 国庆","1006 老人","1024 联合国日","1112 孙中山诞辰纪念","1220 澳门回归纪念","1225 圣诞","1226 毛泽东诞辰纪念" };// ====== 传回农历y年的总天数final private static int yearDays(int y) {int i, sum = 348;for (i = 0x8000; i > 0x8; i >>= 1) {if ((lunarInfo[y - 1900] & i) != 0)sum += 1;}return (sum + leapDays(y));}// ====== 传回农历y年闰月的天数final private static int leapDays(int y) {if (leapMonth(y) != 0) {if ((lunarInfo[y - 1900] & 0x10000) != 0)return 30;elsereturn 29;} elsereturn 0;}// ====== 传回农历y年闰哪个月1-12 , 没闰传回0final private static int leapMonth(int y) {return (int) (lunarInfo[y - 1900] & 0xf);}// ====== 传回农历y年m月的总天数final private static int monthDays(int y, int m) {if ((lunarInfo[y - 1900] & (0x10000 >> m)) == 0)return 29;elsereturn 30;}// ====== 传回农历y年的生肖final public String animalsYear(int year) {final String[] Animals = new String[] { "鼠", "牛", "虎", "兔", "龙", "蛇","马", "羊", "猴", "鸡", "狗", "猪" };return Animals[(year - 4) % 12];}// ====== 传入月日的offset 传回干支, 0=甲子final private static String cyclicalm(int num) {final String[] Gan = new String[] { "甲", "乙", "丙", "丁", "戊", "己", "庚","辛", "壬", "癸" };final String[] Zhi = new String[] { "子", "丑", "寅", "卯", "辰", "巳", "午","未", "申", "酉", "戌", "亥" };return (Gan[num % 10] + Zhi[num % 12]);}// ====== 传入offset 传回干支, 0=甲子final public String cyclical(int year) {int num = year - 1900 + 36;return (cyclicalm(num));}public static String getChinaDayString(int day) {String chineseTen[] = { "初", "十", "廿", "卅" };int n = day % 10 == 0 ? 9 : day % 10 - 1;if (day > 30)return "";if (day == 10)return "初十";elsereturn chineseTen[day / 10] + chineseNumber[n];}/** *//*** 传出y年m月d日对应的农历. yearCyl3:农历年与1864的相差数? monCyl4:从1900年1月31日以来,闰月数* dayCyl5:与1900年1月31日相差的天数,再加40 ?** isday: 这个参数为false---日期为节假日时,阴历日期就返回节假日,true---不管日期是否为节假日依然返回这天对应的阴历日期* @param cal* @return*/public String getLunarDate(int year_log, int month_log, int day_log, boolean isday) {// @SuppressWarnings("unused")int yearCyl, monCyl, dayCyl;//int leapMonth = 0;String nowadays;Date baseDate = null;Date nowaday = null;try {baseDate = chineseDateFormat.parse("1900年1月31日");} catch (ParseException e) {e.printStackTrace(); // To change body of catch statement use// Options | File Templates.}nowadays = year_log + "年" + month_log + "月" + day_log + "日";try {nowaday = chineseDateFormat.parse(nowadays);} catch (ParseException e) {e.printStackTrace(); // To change body of catch statement use// Options | File Templates.}// 求出和1900年1月31日相差的天数int offset = (int) ((nowaday.getTime() - baseDate.getTime()) / 86400000L); dayCyl = offset + 40;monCyl = 14;// 用offset减去每农历年的天数// 计算当天是农历第几天// i最终结果是农历的年份// offset是当年的第几天int iYear, daysOfYear = 0;for (iYear = 1900; iYear < 10000 && offset > 0; iYear++) {daysOfYear = yearDays(iYear);offset -= daysOfYear;monCyl += 12;}if (offset < 0) {offset += daysOfYear;iYear--;monCyl -= 12;}// 农历年份year = iYear;setYear(year); //设置公历对应的农历年份yearCyl = iYear - 1864;leapMonth = leapMonth(iYear); // 闰哪个月,1-12leap = false;// 用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天int iMonth, daysOfMonth = 0;for (iMonth = 1; iMonth < 13 && offset > 0; iMonth++) {// 闰月if (leapMonth > 0 && iMonth == (leapMonth + 1) && !leap) {--iMonth;leap = true;daysOfMonth = leapDays(year);} elsedaysOfMonth = monthDays(year, iMonth);offset -= daysOfMonth;// 解除闰月if (leap && iMonth == (leapMonth + 1))leap = false;if (!leap)monCyl++;}// offset为0时,并且刚才计算的月份是闰月,要校正if (offset == 0 && leapMonth > 0 && iMonth == leapMonth + 1) {if (leap) {leap = false;} else {leap = true;--iMonth;--monCyl;}}// offset小于0时,也要校正if (offset < 0) {offset += daysOfMonth;--iMonth;--monCyl;}month = iMonth;setLunarMonth(chineseNumber[month - 1] + "月"); //设置对应的阴历月份day = offset + 1;if(!isday){//如果日期为节假日则阴历日期则返回节假日//setLeapMonth(leapMonth);for(int i = 0; i < solarHoliday.length; i++){//返回公历节假日名称String sd = solarHoliday[i].split(" ")[0]; //节假日的日期String sdv = solarHoliday[i].split(" ")[1]; //节假日的名称String smonth_v = month_log+"";String sday_v = day_log+"";String smd = "";if(month_log < 10){smonth_v = "0"+month_log;}if(day_log < 10){sday_v = "0"+day_log;}smd = smonth_v+sday_v;if(sd.trim().equals(smd.trim())){return sdv;}}for(int i = 0; i < lunarHoliday.length; i++){//返回农历节假日名称String ld =lunarHoliday[i].split(" ")[0]; //节假日的日期String ldv = lunarHoliday[i].split(" ")[1]; //节假日的名称String lmonth_v = month+"";String lday_v = day+"";String lmd = "";if(month < 10){lmonth_v = "0"+month;}if(day < 10){lday_v = "0"+day;}lmd = lmonth_v+lday_v;if(ld.trim().equals(lmd.trim())){return ldv;}}}if (day == 1)return chineseNumber[month - 1] + "月";elsereturn getChinaDayString(day);}public String toString() {if (chineseNumber[month - 1] == "一" && getChinaDayString(day) == "初一") return "农历" + year + "年";else if (getChinaDayString(day) == "初一")return chineseNumber[month - 1] + "月";elsereturn getChinaDayString(day);// return year + "年" + (leap ? "闰" : "") + chineseNumber[month - 1] +// "月" + getChinaDayString(day);}/*public static void main(String[] args) {System.out.println(new LunarCalendar().getLunarDate(2012, 1, 23));}*/public int getLeapMonth() {return leapMonth;}public void setLeapMonth(int leapMonth) {this.leapMonth = leapMonth;}/*** 得到当前日期对应的阴历月份* @return*/public String getLunarMonth() {return lunarMonth;}public void setLunarMonth(String lunarMonth) {this.lunarMonth = lunarMonth;}/*** 得到当前年对应的农历年份* @return*/public int getYear() {return year;}public void setYear(int year) {this.year = year;}}//关于日历实现代码里0x04bd8, 0x04ae0, 0x0a570的解释:/onlyonecoder/article/details/8484118///*** 日历显示activity***/public class CalendarActivity extends Activity implements OnGestureListener {private GestureDetector gestureDetector = null;private CalendarAdapter calV = null;private GridView gridView = null;private TextView topText = null;private static int jumpMonth = 0; //每次滑动,增加或减去一个月,默认为0(即显示当前月)private static int jumpYear = 0; //滑动跨越一年,则增加或者减去一年,默认为0(即当前年)private int year_c = 0;private int month_c = 0;private int day_c = 0;private String currentDate = "";private Bundle bd=null;//发送参数private Bundle bun=null;//接收参数private String ruzhuTime;private String lidianTime;private String state="";public CalendarActivity() {Date date = new Date();SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d");currentDate = sdf.format(date); //当期日期year_c = Integer.parseInt(currentDate.split("-")[0]);month_c = Integer.parseInt(currentDate.split("-")[1]);day_c = Integer.parseInt(currentDate.split("-")[2]);}@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);ActivityList.activityList.add(this);setContentView(yout.calendar);bd=new Bundle();//outbun=getIntent().getExtras();//inif(bun!=null&&bun.getString("state").equals("ruzhu")){state=bun.getString("state");System.out.println("%%%%%%"+state);}else if(bun!=null&&bun.getString("state").equals("lidian")){state=bun.getString("state");System.out.println("|||||||||||"+state);}gestureDetector = new GestureDetector(this);// bd=new Bundle();calV = new CalendarAdapter(this,getResources(),jumpMonth,jumpYear,year_c,month_c,day_c);addGridView();gridView.setAdapter(calV);topText = (TextView) findViewById(_month);addTextToTopTextView(topText);}@Overridepublic boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY) {int gvFlag = 0; //每次添加gridview到viewflipper中时给的标记if (e1.getX() - e2.getX() > 120) {//像左滑动addGridView(); //添加一个gridViewjumpMonth++; //下一个月calV = new。