将DAY_OF_MONTH或DAY_OF_YEAR添加到Calendar对象之间有什么区别? [英] What's the difference between adding DAY_OF_MONTH or DAY_OF_YEAR to a Calendar object?
本文介绍了将DAY_OF_MONTH或DAY_OF_YEAR添加到Calendar对象之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将某个日期增加1天。我创建了一个Calendar对象,如:
I want to increase a certain date by 1 day. I create a Calendar object like:
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 2012);
cal.set(Calendar.MONTH, 0);
cal.set(Calendar.DAY_OF_MONTH, 31);
然后,为了增加1天,我可以做两件事:
Then, for increasing it by 1 day, I can do 2 things :
cal.add(Calendar.DAY_OF_MONTH, 1);
OR
cal.add(Calendar.DAY_OF_YEAR, 1);
还有其他DAY常量,但我使用上述两种方法获得相同的结果将这一天增加1.在这种情况下,我会得到两个不同的结果吗?
There are also other "DAY" constants, but I get the same result using the above 2 methods of increasing the day by 1. In which case will I get different results for the two?
推荐答案
对于添加它真的没什么区别,但是这个
For adding it really makes no difference, but this
Calendar c = Calendar.getInstance();
System.out.println(c.get(Calendar.DAY_OF_MONTH));
System.out.println(c.get(Calendar.DAY_OF_YEAR));
打印
28
363
这篇关于将DAY_OF_MONTH或DAY_OF_YEAR添加到Calendar对象之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文