Formatting seconds and minutes

前端 未结 4 1673
孤独总比滥情好
孤独总比滥情好 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:10

    A real lazy way of doing this as long as you know you won't have more than 60 minutes is to just make a date and use SimpleDateFormat

    public void onTick(long millisUntilFinished) {
         SimpleDateFormat dateFormat = new SimpleDateFormat("mm:ss");
         dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
         Date date = new Date(millisUntilFinished);
         text.setText("Time left:" + dateFormat.format(date));
    }
    

提交回复
热议问题