Formatting seconds and minutes

前端 未结 4 1674
孤独总比滥情好
孤独总比滥情好 2020-12-31 07:19

I need to format seconds and minutes from milliseconds. I am using countdownTimer. does anyone have sugestions? I looked at joda time. But all i need is a format so i have 1

4条回答
  •  灰色年华
    2020-12-31 08:25

    You could do it using the standard Date formatting classes, but that might be a bit heavy-weight. I would just use the String.format method. For example:

    int minutes = time / (60 * 1000);
    int seconds = (time / 1000) % 60;
    String str = String.format("%d:%02d", minutes, seconds);
    

提交回复
热议问题