I want return millisecond to time
But my code not work !
long ms = 86400000;
long s = ms % 60;
long m = (ms / 60) % 60;
long h = (ms / (60 * 60)) % 24;
String timeFind = String.format("%d:%02d:%02d", h, m, s);
You could use SimpleDateFormat
, but be aware that you should set both the time zone and the locale appropriately:
DateFormat formatter = new SimpleDateFormat("HH:mm:ss", Locale.US);
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
String text = formatter.format(new Date(millis));
The time zone part is important, as otherwise it will use the system-default time zone, which would usually be inappropriate. Note that the Date
here will be on January 1st 1970, UTC - assuming your millisecond value is less than 24 hours.
See more on this question at Stackoverflow