import java.util.Calendar;
public class LazyTest {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
cal.set(2003, 7, 31);
cal.set(Calendar.MONTH , 8);
System.out.println(cal.getTime());
cal.set(Calendar.DATE, 5);
System.out.println(cal.getTime());
}
}
运行结果
Wed Oct 01 21:02:26 CST 2003
Sun Oct 05 21:02:26 CST 2003
set(f,value)方法将日历字段f更改为value,此外还设置了一个内部成员变量,
已指示日历字段f已经被更改,但是,Calendar所代表的时间却不会立即修改,
直到下次调用get(),add(),getTime()方法时才会重新计算日历的时间
优势:延迟修改,多次调用set()不会触发多次不必要的计算
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有