Reputation: 67
I'm creating a prayer app. In my app, I calculate upcoming prayer remaining time(by comparing current time) and my countdown timer starts. But, when last prayer(Isha) countdown timer ends then, I've to calculate countdown timer for tomorrow first(Fajr) prayer with current time.
I don't know how to calculate remaining time for tomorrow first prayer?
I've tomorrow first prayer(fajr) time. Please help.
Upvotes: 2
Views: 1059
Reputation: 3296
If you need to use standard java classes then Calendar class is the best choice here. http://developer.android.com/reference/java/util/Calendar.html
Simple code:
Calendar nextDayCal = Calendar.getInstance();
nextDayCal.add(Calendar.DAY_OF_YEAR, 1);
nextDayCal.set(Calendar.MILLISECOND, 0);
nextDayCal.set(Calendar.SECOND, 0);
nextDayCal.set(Calendar.MINUTE, 0);
nextDayCal.set(Calendar.HOUR_OF_DAY, 0);
Calendar nowCal = Calendar.getInstance();
int hourDif = nextDayCal.get(Calendar.HOUR_OF_DAY) - nowCal.get(Calendar.HOUR_OF_DAY);
Upvotes: 2