Skip to content Skip to sidebar Skip to footer

Display Days, Hours, Minutes In Between 2 Dates In Java

I need to display a countdown timer between a specified date in the future and now in the format Days:Hours:Minutes. So for example the end date is 4th december 1:30 PM 2013 and ri

Solution 1:

I guess you have two java.util.Date objects to compare. First you wanna have some kind of timer that gets executed every N seconds. Handler.postDelayed() works just fine for that. Every time it executes, you use timeMs = futureDate.getTime() - System.currentTimeMillis(). This gives you the time difference in milli seconds. Then you only need to convert this to the desired format: e.g. seconds = timeMs / 1000 % 60.


Post a Comment for "Display Days, Hours, Minutes In Between 2 Dates In Java"