Mansoor Ahmad
Mansoor Ahmad

Reputation: 67

How to compare current time with next day time in Android?

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

Answers (1)

Viktor Yakunin
Viktor Yakunin

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

Related Questions