如何从Calendar对象获取以毫秒为单位的时间以便在Alarm Manager中设置间隔我使用以下代码:
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), interval, sender);
我获得一个月MilliSeconds的interval
计算如下:
Calendar monthCal = Calendar.getInstance();
monthCal.clear();
monthCal.setTimeInMillis(System.currentTimeMillis());
monthCal.add(Calendar.MONTH, 1);
interval = monthCal.getTimeInMillis();
但我没有得到任何重复的警报。
答案 0 :(得分:1)
您可以执行以下操作:
Calendar c = Calendar.getInstance();
c.set(year,month,1); // Set the year and month you want milliseconds for
long daysInMonth = c.getActualMaximum(Calendar.DATE); //Get how many days this month have
long millisInMonth = daysInMonth*dayMillis; //Multiply the amount of days with how many milliseconds a day consists of (86400000L)