使用Java中的Calendar的add()方法添加30天以上 [英] add more than 30 days with Calendar's add() method in Java
本文介绍了使用Java中的Calendar的add()方法添加30天以上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不太确定在向Java Calendar对象添加超过30天时使用的字段。 Calendar.DAY_OF_MONTH
和 Calendar.DAY_OF_YEAR
之间有什么区别吗?
I'm not quite sure what field to use when adding more than 30 days to a Java Calendar object. Is there any difference in between Calendar.DAY_OF_MONTH
and Calendar.DAY_OF_YEAR
?
示例:
GregorianCalendar d = new GregorianCalendar();
d.add(Calendar.DAY_OF_YEAR, 90);
vs
GregorianCalendar d = new GregorianCalendar();
d.add(Calendar.DAY_OF_MONTH, 90);
谢谢。
推荐答案
我不认为这会产生影响,当你调用add。当你调用getter时,区别很重要。
I don't think it makes a difference when you call add. The distinction is important when you call the getters.
两种方法都很好,对吧?
Both methods work fine, right? For more than 30 days, as well as negative amounts.
GregorianCalendar#add(确实复杂)的来源包含此部分:
The (admittedly complicated) source for GregorianCalendar#add has this section:
case DAY_OF_MONTH: // synonym of DATE
case DAY_OF_YEAR:
case DAY_OF_WEEK:
break;
这篇关于使用Java中的Calendar的add()方法添加30天以上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文