Reputation: 315
I have a list of alarms specified by the user like a typical alarm clock app as:
I'm hand-writing a function to go through a list of times specified this way and determine which is the next up-coming alarm compared to current time. I'll use AlarmManager ultimately to scheduling the next upcoming alarm once I determine which alarm is next. I have considered Date, Time, and GregorianCalendar classes because they have before() and after() methods but they are all a pain to construct given my parameters. Is there a better way than writing all the date/time subtraction math myself?
Upvotes: 0
Views: 247
Reputation: 22437
You can use date object.Here is video lesson I found in youtube. create digital clock
while(time == 0){
Calendar calen = new GregorianCalendar();
int hr = calen.get(Calendar.HOUR);
int min = calen.get(Calendar.MINUTE);
int sec = calen.get(Calendar.SECOND);
int AP = calen.get(Calendar.AM_PM);
String d_n = "";
if(AP == 1){
d_n = "PM";
}else{
d_n = "AM";
}
}
Upvotes: 0
Reputation: 56
You could use the Calendar class for aiding the construction of dates. Then with the getDate method you could get milliseconds and deal with them for finding the closest alarm. Check an example of usage of Calendar here http://www.tutorialspoint.com/java/util/calendar_add.htm
Upvotes: 0