这是一个简单的问题,但我没有得到它的工作。已用时间格式HH:mm:ss
我每秒递增一个变量并将其设置在一个格里高利的日历中,以毫秒为单位。
而我正在使用这种格式HH:mmss
来呈现elpased时间。
问题是,小时开始显示01而不是00.例如,1分35秒后显示的是:01:01:35
而不是00:01:35
。
问题出在哪里?
有重要的代码:
GregorianCalendar timeIntervalDone = new GregorianCalendar(TimeZone.getTimeZone("GMT-1")); //initially I didn't have the TimeZone set, but no difference
SimpleDateFormat dateTimeIntervalFormat = new SimpleDateFormat("HH:mm:ss");
public String getTimeIntervalDoneAsString() {
timeIntervalDone.setTimeInMillis(mTimeIntervalDone); //mTimeIntervalDone is the counter: 3seccond -> mTimeIntervalDone = 3000
return dateTimeIntervalFormat.format(timeIntervalDone.getTime());
}
缺点:只适用于小于一天(24小时)的时间间隔。 –