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

前端 未结 6 598
栀梦
栀梦 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:06

    You should get SimpleDateFormat with Locale argument.

    public static String getDateFromMillis(long millis) {
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
        return formatter.format(new Date(millis));
    }
    

提交回复
热议问题