Search code examples
androidjsondate-format

How to convert number to hour and minute in android


In my application i should show hour and minute and i get this numbers from server with this sample :
Json :

{
  data:{
    time:84561
  }
}

i should get this number from time and show it with this format

**hh : mm : ss**

I can get number of time, but i can't convert this to **hh : mm : ss** .

How can i it?


Solution

  • long timeSec= 84561;// Json output
    int hours = (int) timeSec/ 3600;
    int temp = (int) timeSec- hours * 3600;
    int mins = temp / 60;
    temp = temp - mins * 60;
    int secs = temp;
    
    String requiredFormat = hours+ ": "+mins+": "+secs;//hh:mm:ss formatted string