Search code examples
androidtimecountdown

Android : countdown and format time


I have a data in milliseconds and with CountDown class I would to display the time in this format : Days : Houres : Minutes : Seconds. If I do milliseconds / 1000 I have the total second If I do (milliseconds / 1000) / 60 I have the total minutes Etc but how can I display a countdown in this format : 2dayes : 21houres : 56 minutes : 00seconds

Thanks


Solution

  • you should use DateFormat or SimpleDateFormat, see http://developer.android.com/reference/java/text/DateFormat.html

    First, you should convert your milliseconds to Date.

    Date date = new Date();
    date.setTime(millis);
    

    Then you could use DateFormat to format your timestamp to human-readable string.