Calendar#get(Calendar.HOUR_OF_DAY)vs TimeUnits.MILLISECONDS.toHours()

时间:2015-03-05 12:34:58

标签: java android calendar

你们知道为什么会发生这种情况,为什么Calendar会为1返回hours,而绝对不是1,而0.008就是这个具体案例:

millisUntilFinished = 30 * 1000

public void test(long millisUntilFinished) {
final Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(millisUntilFinished);
Timber.i("Hours: " + cal.get(Calendar.HOUR_OF_DAY));
Timber.i("Hours using TimeUnit: " + TimeUnit.MILLISECONDS.toHours(millisUntilFinished));
}

输出:

Hours: 01
Hours using TimeUnit: 00

1 个答案:

答案 0 :(得分:0)

时区。如果您的Calendar位于UTC+1,那就是您将获得的结果。