Calendar类中的complete()
方法执行以下操作:
protected void complete()
填充日历字段中未设置的任何字段。首先,如果从日历字段值没有计算出时间值(距离纪元的毫秒偏移量),则调用computeTime()方法。然后,调用computeFields()方法计算所有日历字段值。
complete()
方法的代码如下:protected void complete()
{
if (!isTimeSet)
updateTime();
if (!areFieldsSet || !areAllFieldsSet) {
computeFields(); // fills in unset fields
areAllFieldsSet = areFieldsSet = true;
}
}
我的问题是这个循环工作的意义是什么?首先,从...获取值
protected int[] fields
用于更新值的
long time
使用
computeTime()
方法。然后使用time
的值,通过computeFields()
方法更新fields
中的值。在调用computeTime()
方法之后,time
和fields
中的值将保持同步,对吗?或者我漏掉了什么重要的步骤吗?对于那些可能会问为什么这么重要的人,因为在日历中重新计算时间的顺序经常会改变我们从
getTime()
中获取的时间(或者这就是我读到的)。