Android 中的 RRULE
我正在尝试在日历中设置每周星期一早上 9 点提醒 以下是代码
final int[] preTimings = {9, 12, 18};
Calendar calendar = Calendar.getInstance(Locale.getDefault());
ContentValues newEvent = new ContentValues();
int month = calendar.get(Calendar.MONTH);
int date = calendar.get(Calendar.DATE);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DATE, date);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
for(int i = 0; i < preTimings.length; i++{
calendar.set(Calendar.HOUR_OF_DAY, preTimings[i]);
long timeInMillis = calendar.getTimeInMillis();
newEvent.put(CalendarContract.Events.CALENDAR_ID, 1);
newEvent.put(CalendarContract.Events.TITLE, preTitle[i]);
newEvent.put(CalendarContract.Events.DTSTART, timeInMillis);
newEvent.put(CalendarContract.Events.DTEND, timeInMillis + 60000);
newEvent.put(CalendarContract.Events.RRULE, "FREQ=WEEKLY;BYDAY=MO");
newEvent.put(CalendarContract.Events.HAS_ALARM, true);
newEvent.put(CalendarContract.Events.EVENT_TIMEZONE, "GMT-05:30");
因此,该程序在每周一正确设置中午 12 点和下午 6 点,但由于某种原因,它在每周周二设置上午 9 点。 我不知道这里出了什么问题。我什至尝试在在线计算器中转换 timeInMillis 以了解结果是什么,但它们是正确的。
I am trying to set weekly monday reminder in calendar at 9 a.m.
Following is the code
final int[] preTimings = {9, 12, 18};
Calendar calendar = Calendar.getInstance(Locale.getDefault());
ContentValues newEvent = new ContentValues();
int month = calendar.get(Calendar.MONTH);
int date = calendar.get(Calendar.DATE);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DATE, date);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
for(int i = 0; i < preTimings.length; i++{
calendar.set(Calendar.HOUR_OF_DAY, preTimings[i]);
long timeInMillis = calendar.getTimeInMillis();
newEvent.put(CalendarContract.Events.CALENDAR_ID, 1);
newEvent.put(CalendarContract.Events.TITLE, preTitle[i]);
newEvent.put(CalendarContract.Events.DTSTART, timeInMillis);
newEvent.put(CalendarContract.Events.DTEND, timeInMillis + 60000);
newEvent.put(CalendarContract.Events.RRULE, "FREQ=WEEKLY;BYDAY=MO");
newEvent.put(CalendarContract.Events.HAS_ALARM, true);
newEvent.put(CalendarContract.Events.EVENT_TIMEZONE, "GMT-05:30");
So this program is setting the 12 p.m and 6 p.m correctly on Mondays every week but for some reason it is setting the 9 a.m on Tuesdays every week.
I don't know what is wrong over here. I even tried converting the timeInMillis in an online calculator to know what is the result, but they are correct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以问题出在最后一行,尽管我已经明确声明了时区,但它的设置不正确。
因此,
它应该是
仍然不知道为什么它在上午 11 点及以上时间有效。有点奇怪
So the issue was on the last line, even though i have specifically declared the timezone, it was setting it incorrectly.
So instead of
It should be
Still no idea why it worked for times 11 a.m and above. Kinda weird