java编辑日历的代码,java制作android 日历代码分享

代码很简单,就不多废话了

//读取日历事件

public static void getCalendarInfo(Activity activity,String tag){

String[] projection = new String[]{CalendarContract.Events._ID,CalendarContract.Events.TITLE};

ContentResolver cr = activity.getContentResolver();

Cursor cursor = cr.query(CalendarContract.Events.CONTENT_URI, projection, null, null, null);

int idIndex = cursor.getColumnIndexOrThrow(CalendarContract.Events._ID);

Log.d(tag, cursor.getCount()+"");

int titleIndex = cursor.getColumnIndexOrThrow(CalendarContract.Events.TITLE);

while (cursor.moveToNext()) {

String id = cursor.getString(idIndex);

String title = cursor.getString(titleIndex);

Log.d(tag, id+":"+title);

}

cursor.close();

}

//插入事件

public static void addCalendarEvent(Activity activity,String tag){

Intent intent = new Intent(Intent.ACTION_INSERT,CalendarContract.Events.CONTENT_URI);

Log.d(tag, CalendarContract.Events.CONTENT_URI.toString());

intent.putExtra(CalendarContract.Events.TITLE, "Launch");

intent.putExtra(CalendarContract.Events.DESCRIPTION, "Launch,Android app");

intent.putExtra(CalendarContract.Events.EVENT_LOCATION, "baidu.com");

Calendar calendar = Calendar.getInstance();

calendar.setTime(new Date());

intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, calendar.getTimeInMillis());

intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);

activity.startActivity(intent);

}

//编辑日历事件

public static void editCalendarEvent(Activity activity,String tag){

long rowId = 1;

Uri editUri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI,rowId);

Log.d(tag, CalendarContract.Events.CONTENT_URI.toString());

Intent intent = new Intent(Intent.ACTION_EDIT,editUri);

intent.putExtra(CalendarContract.Events.EVENT_LOCATION, "NJ");

Calendar calendar = Calendar.getInstance();

calendar.set(2015, 2, 17, 12, 1, 1);

intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, calendar.getTimeInMillis());

intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);

activity.startActivity(intent);

}

//查看日历

public static void viewCalendar(Activity activity,String tag){

Calendar calendar = Calendar.getInstance();

calendar.set(2015, 2, 17, 12, 1, 1);

Uri uri = Uri.parse("content://com.android.calendar/time/"+calendar.getTimeInMillis());

Intent intent = new Intent(Intent.ACTION_VIEW,uri);

activity.startActivity(intent);

}

以上就是本文给大家分享的全部代码了,希望对大家学习java能够有所帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个基于8051单片机的简单日历代码: ``` #include<reg51.h> unsigned char code month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; // 月份天数数组 unsigned char code week[7]={"SunMonTueWedThuFriSat"}; // 星期数组 unsigned char year=2021,month=1,day=1,weekday=0; // 初始时间为2021年1月1日 void delay(unsigned int t) { unsigned int i,j; for(i=0;i<t;i++) for(j=0;j<120;j++); } void display(unsigned char num) { P2=num; delay(5); } void main() { unsigned char i,j; TMOD=0x01; // 定时器0工作在方式1 TH0=(65536-50000)/256; // 定时50ms TL0=(65536-50000)%256; IE=0x82; // 允许定时器0断,允许全局断 TR0=1; // 启动定时器0 while(1) { for(i=1;i<=12;i++) { for(j=1;j<=month[i];j++) { weekday++; if(weekday==7) weekday=0; if(year%400==0||(year%4==0&&year%100!=0)) if(i==2&&j==29) // 闰年2月29日 break; display(i/10); // 显示月份十位数 display(i%10); // 显示月份个位数 display(j/10); // 显示日期十位数 display(j%10); // 显示日期个位数 display(weekday*3); // 显示星期 delay(1000); // 延时1秒 } if(year%400==0||(year%4==0&&year%100!=0)) if(i==2) month[2]=29; // 闰年 month[2]=28; // 平年 } year++; // 年份加1 } } void timer0() interrupt 1 { static unsigned char cnt=0; TH0=(65536-50000)/256; // 定时50ms TL0=(65536-50000)%256; cnt++; if(cnt>=20) // 每1秒钟更新一次时间 { cnt=0; weekday++; if(weekday==7) weekday=0; day++; if(day>month[month]) { day=1; month++; if(month>12) { month=1; year++; } } } } ``` 这个程序通过定时器0来产生时钟节拍,每1秒钟更新一次时间。在主循环,程序循环遍历当年的每个月份和日期,并在数码管上显示出来。同时,根据计算出来的星期数,在数码管上显示出来。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值