by
6,010 13

Convert Milliseconds to Time hours, minutes and seconds as String.

Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/3857386/Convert-Milliseconds-to-Time-hours--minu?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
public class Main { public static void main(String[] args) { long totalTimeInMils=6003000; convertMillisToTime(totalTimeInMils); //Covert from Dates String strStartDate = "2018/08/16 17:10:00"; String strEndDate = "2018/08/16 17:20:01"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date = sdf.parse(strStartDate); Date endDate = sdf.parse(strEndDate); long millis = (endDate.getTime()- date.getTime()); convertMillisToTime(millis); } public static String convertMillisToTime(long Millis){ String convert = String.format("Total Time Taken: %d hour(s), %d minute(s), and %d second(s)", Millis/(1000*60*60), (Millis%(1000*60*60))/(1000*60), ((Millis%(1000*60*60))%(1000*60))/1000); System.out.println(convert); return convert; } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus