How to convert the seconds in this format “HH:mm:ss”

前端 未结 6 597
栀梦
栀梦 2021-02-06 23:31

I want to convert the second/milliseconds in this format \"HH:mm:ss\" (for esamples, from 5 seconds to 00:00:05). I tried to get that format in this way:

int mil         


        
6条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-07 00:12

    I got this to work. Let me know if it works for you. Seems like a lot of lines to do something seemingly simple..

        int millis = 5000;
        TimeZone tz = TimeZone.getTimeZone("UTC");
        SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
        df.setTimeZone(tz);
        String time = df.format(new Date(millis));
        System.out.println(time);
    

提交回复
热议问题