android添加时间,添加日期和时间到Android日历

Date date = null;

long starttime,endtime;

try {

date = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:Ss z").parse(tit1);

} catch (java.text.ParseException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

,并添加此日期使用下面的日历转换这个字符串星期一,2013年2月11日08:00:00 CST最新代码

try{

Calendar cal = Calendar.getInstance();

starttime=date.getTime();

endtime=date.getTime();

Intent intent = new Intent(Intent.ACTION_EDIT);

intent.setType("vnd.android.cursor.item/event");

intent.putExtra("beginTime",starttime);

intent.putExtra("allDay", true);

intent.putExtra("rrule", "FREQ=YEARLY");

intent.putExtra("endTime", endtime);

intent.putExtra("title",tit);

}

catch(Exception e)

{

}

事件被添加像周一,2月11日2013年 我需要添加事件如下所示

From: Mon, 11 Feb 2013 08:00AM

To: Mon, 11 Feb 2013 08:30AM

如何使用以下字符串和简单日期格式样式来执行此操作。

P.S. ::开始时间&结束时间是long类型

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Android Studio 中将日程添加到系统日历中,可以按照以下步骤操作: 1. 添加日历权限: 在应用程序的 `AndroidManifest.xml` 文件中添加 `WRITE_CALENDAR` 权限。例如: ```xml <uses-permission android:name="android.permission.WRITE_CALENDAR" /> ``` 2. 创建日历事件: 在需要添加日历事件的地方,使用以下代码创建日历事件: ```java ContentResolver cr = getContentResolver(); ContentValues values = new ContentValues(); values.put(CalendarContract.Events.DTSTART, startMillis); values.put(CalendarContract.Events.DTEND, endMillis); values.put(CalendarContract.Events.TITLE, "My Event"); values.put(CalendarContract.Events.DESCRIPTION, "Description of my event"); values.put(CalendarContract.Events.CALENDAR_ID, 1); values.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID()); Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values); long eventId = Long.parseLong(uri.getLastPathSegment()); ``` 其中 `startMillis` 和 `endMillis` 分别是事件的开始时间和结束时间,可以使用 `Calendar` 类的 `getTimeInMillis()` 方法将日期转换为毫秒数。`CALENDAR_ID` 是日历账户的 ID,可以使用 `CalendarContract.Calendars` 表查询获得。`EVENT_TIMEZONE` 是事件的时区,可以使用 `TimeZone.getDefault().getID()` 获取本地时区。 3. 添加提醒: 如果需要为日历事件添加提醒,可以使用以下代码: ```java int minutes = 60; ContentValues reminderValues = new ContentValues(); reminderValues.put(CalendarContract.Reminders.MINUTES, minutes); reminderValues.put(CalendarContract.Reminders.EVENT_ID, eventId); reminderValues.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT); cr.insert(CalendarContract.Reminders.CONTENT_URI, reminderValues); ``` 其中 `minutes` 是提醒的时间,单位为分钟。`METHOD_ALERT` 表示使用默认的提醒方式,可以根据需要使用其他方式。 以上就是在 Android Studio 中将日程添加到系统日历的基本步骤。需要注意的是,要测试此功能,需要在真机上测试,因为模拟器默认没有日历应用。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值