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?
Pass your Number or timestamp and convert to milliseconds for hour and minute.use the below code.
Try This Logic Use it As per Requirement
Output
here
Java 9 answer
Unfortunately in Java 8
Duration
does not lend itself well to formatting. The methods I use in the snippet are introduced in Java 9 and will calculate the values for hh, mm and ss. ThenString.format()
does the rest.I know you cannot use this on Andriod (yet), but I wanted to have this answer stand here for others who can use Java 9, now or in the future.
Very simple
If this is unix time then it will be converted into human readable time format with this snippet.
You can use
new Date(unix);
and with below function you can get formatted date. You can format in different style.For more information check this link already answer : Convert unix time stamp to date in java
Referance:
https://developer.android.com/reference/android/text/format/DateUtils.html
https://developer.android.com/reference/android/text/format/Time.html