在Java中的日历对象中添加DAY_OF_MONTH或DAY_OF_YEAR的区别是什么? [英] What's the difference b/w adding DAY_OF_MONTH or DAY_OF_YEAR to a Calendar object in Java?
本文介绍了在Java中的日历对象中添加DAY_OF_MONTH或DAY_OF_YEAR的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将某个日期增加1天。我创建一个日历对象,如:
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);
或
cal.add(Calendar.DAY_OF_YEAR, 1);
还有其他DAY常量,但是我使用上述2种方法得到相同的结果增加一天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
这篇关于在Java中的日历对象中添加DAY_OF_MONTH或DAY_OF_YEAR的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文