這是一個簡單的問題,但我沒有得到它的工作。已用時間格式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小時)的時間間隔。 –