How to convert Milliseconds to “X mins, x seconds” in Java?

后端 未结 27 1776
夕颜
夕颜 2020-11-22 03:59

I want to record the time using System.currentTimeMillis() when a user begins something in my program. When he finishes, I will subtract the current Syste

27条回答
  •  囚心锁ツ
    2020-11-22 04:34

    Just to add more info if you want to format like: HH:mm:ss

    0 <= HH <= infinite

    0 <= mm < 60

    0 <= ss < 60

    use this:

    int h = (int) ((startTimeInMillis / 1000) / 3600);
    int m = (int) (((startTimeInMillis / 1000) / 60) % 60);
    int s = (int) ((startTimeInMillis / 1000) % 60);
    

    I just had this issue now and figured this out

提交回复
热议问题